While reading json from files, using polars give exception when it has empty json. But it is not the same in pandas. I have some files with only key and not value.
Is polars still primitive and not matured like pandas? which package to use?
Polars
from io import StringIO
import polars as pl
print(pl.read_json(StringIO('{"key":{}}')))
gives exception
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("a StructArray must contain at least one field"))
Pandas
from io import StringIO
import pandas as pd
print(pd.read_json(StringIO('{"key":{}}')))
works without exception, gives output as
Empty DataFrame
Columns: [key]
Index: []
Neo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Pandas is mature and Polars is comparatively a new library. There is an issue exists, which is same as yours, refer to this bug link,
Polars Issue Link
Either you can use exception handling with polars for this scenario or go with pandas.
1