Explorer.DataFrame - load_ndjson json


I’m trying to load a json API message with Explorer.DataFrame.

My api is returning a list like bellow:

resp = [%{"idade" => "8", "nome" => "Mirela"}, %{"idade" => "40", "nome" => "Sergio"}]

When I try to run the following code:

require Explorer.DataFrame, as: DF
DF.load_ndjson!(Jason.encode!(resp), lazy: true)

I got an error:

** (ErlangError) Erlang error: :nif_panicked
    (explorer 0.5.7) Explorer.PolarsBackend.Native.df_load_ndjson("...

But if I change to read the first element it works as well.

require Explorer.DataFrame, as: DF

How to read the entire data ?

Thank you.

The ndjson parser expects JSON objects separated by newlines - for instance, here’s an example from Explorer’s tests:

That is not what Jason.encode!(resp) will produce - that result will have [ at the beginning and , between the objects. You’d need to encode each item in resp separately.


In general, re-encoding like that should make you suspect that you’re not using the best API for your situation.

The better choice is Explorer.DataFrame.new, in particular the last example labeled “From row data:”.