Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str.json_decode panics on {} entry #15720

Open
2 tasks done
stinodego opened this issue Apr 17, 2024 · 1 comment
Open
2 tasks done

str.json_decode panics on {} entry #15720

stinodego opened this issue Apr 17, 2024 · 1 comment
Labels
A-panic Area: code that results in panic exceptions bug Something isn't working python Related to Python Polars

Comments

@stinodego
Copy link
Member

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

s = pl.Series(["{}"])
result = s.str.json_decode()
print(result)

Log output

thread '<unnamed>' panicked at crates/polars-arrow/src/array/struct_/mod.rs:117:52:
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("a StructArray must contain at least one field"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/stijn/code/polars/py-polars/repro.py", line 4, in <module>
    result = s.str.json_decode()
             ^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/series/utils.py", line 107, in wrapper
    return s.to_frame().select_seq(f(*args, **kwargs)).to_series()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/dataframe/frame.py", line 7709, in select_seq
    return self.lazy().select_seq(*exprs, **named_exprs).collect(_eager=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/lazyframe/frame.py", line 1683, in collect
    return wrap_df(ldf.collect())
                   ^^^^^^^^^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("a StructArray must contain at least one field"))

Issue description

Brought up in #9216

Empty structs do not exist, so this will error.

Expected behavior

This should raise a proper error.

Installed versions

main

@stinodego stinodego added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer A-panic Area: code that results in panic exceptions and removed needs triage Awaiting prioritization by a maintainer labels Apr 17, 2024
@cmdlineluser
Copy link
Contributor

It has popped up in read_json / read_ndjson also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-panic Area: code that results in panic exceptions bug Something isn't working python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

2 participants