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

Creating frames with List(Struct(...Categorical)) fails depending on order #19943

Open
2 tasks done
billylanchantin opened this issue Nov 23, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@billylanchantin
Copy link
Contributor

billylanchantin commented Nov 23, 2024

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
dtype = pl.datatypes.List(pl.datatypes.Struct({"field": pl.datatypes.Categorical()}))
pl.DataFrame({"col": [[], [{"field": "example"}]]}, schema={"col": dtype})

Log output

thread '<unnamed>' panicked at /Users/runner/work/polars/polars/crates/polars-arrow/src/array/binview/mod.rs:336:9:
assertion failed: i < self.len()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/.venv/lib/python3.12/site-packages/polars/dataframe/frame.py", line 1182, in __repr__
    return self.__str__()
           ^^^^^^^^^^^^^^
  File "/path/to/.venv/lib/python3.12/site-packages/polars/dataframe/frame.py", line 1179, in __str__
    return self._df.as_str()
           ^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: assertion failed: i < self.len()

Issue description

Creating the dataframe can fail when the first element of a List(Struct(...Categorical)) is an empty list.

Expected behavior

The data for this dataframe is valid, so creating it should succeed. If we swap the order of the inner list so the [] is no longer the head of the list, it actually does succeed:

pl.DataFrame({"col": [[{"field": "example"}], []]}, schema={"col": dtype})
# shape: (2, 1)
# ┌─────────────────┐
# │ col             │
# │ ---             │
# │ list[struct[1]] │
# ╞═════════════════╡
# │ [{"example"}]   │
# │ []              │
# └─────────────────┘

Installed versions

--------Version info---------
Polars:              1.14.0
Index type:          UInt32
Platform:            macOS-12.5-x86_64-i386-64bit
Python:              3.12.3 (v3.12.3:f6650f9ad7, Apr  9 2024, 08:18:48) [Clang 13.0.0 (clang-1300.0.29.30)]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           0.3.3
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
google.auth          2.34.0
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         <not installed>
numpy                2.1.0
openpyxl             <not installed>
pandas               2.2.3
pyarrow              17.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           2.0.36
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@billylanchantin billylanchantin added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

1 participant