Closed cebaa closed 3 weeks ago
Not sure how relevant it is, but the actual exception comes from arrow2
pl.read_json(b'{"j":{}}')
# thread '<unnamed>' panicked at
# 'called `Result::unwrap()` on an `Err` value: OutOfSpec("A StructArray must contain at least one field")',
# /Users/user/.cargo/git/checkouts/arrow2-8a2ad61d97265680/d5c78e7/src/array/struct_/mod.rs:122:52
^^^^^^
It also happens with empty lists #7355
pl.read_json(b'{"j":[]}')
Hit by this too when reading lots of json files from a directory. While this gets fixed is there a way to catch the error effectively? Exception
doesn't seem to work?
try:
pl.read_json(b'{"j":{}}')
except Exception as e:
print("caught exception")
@DaveParr Looks like PolarsPanicError does it:
try:
pl.read_json(b'{"j":{}}')
except pl.PolarsPanicError as e:
print("caught exception")
Appears to not be unique to JSON, converting from Pandas like this:
import pandas as pd
import polars as pl
df = pd.DataFrame({"a": [{}]})
boom = pl.from_pandas(df)
Will cause the same issue.
Could it just be a generic issue when converting any empty structure?
@naanselmo You can open a new issue for that one.
Checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of Polars.
Reproducible example
Issue description
The above code fails with:
Expected behavior
Based on the merged PR https://github.com/pola-rs/polars/pull/6039 I'd assume this would produce an empty struct instead.
Installed versions