Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Polars gives exception for empty json, but Pandas works

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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: []

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading