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

sum_horizontal + list.explode PanicException instead of ShapeError #19336

Closed
2 tasks done
cmdlineluser opened this issue Oct 21, 2024 · 0 comments · Fixed by #20130
Closed
2 tasks done

sum_horizontal + list.explode PanicException instead of ShapeError #19336

cmdlineluser opened this issue Oct 21, 2024 · 0 comments · Fixed by #20130
Assignees
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@cmdlineluser
Copy link
Contributor

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

df = pl.DataFrame({"a": [[1, 2], None], "b": [[3, 4], [5, 6]]})

df.select(pl.sum_horizontal(pl.all().list.explode()))
# thread '<unnamed>' panicked at crates/polars-core/src/chunked_array/ops/arity.rs:865:14:
# Cannot apply operation on arrays of different lengths
# PanicException: Cannot apply operation on arrays of different lengths

Log output

No response

Issue description

It seems to happen for mean_horizontal also.

All other horizontal methods produce a ShapeError.

df.select(pl.all_horizontal(pl.all().list.explode()))
# ShapeError: cannot evaluate two Series of different lengths (3 and 4)
# Error originated in expression: '[(col("a").explode()) & (col("b").explode())]'

Expected behavior

Error instead of panic.

Installed versions

--------Version info---------
Polars:               1.10.0
Index type:           UInt32
Platform:             macOS-13.6.1-arm64-arm-64bit
Python:               3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              15.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@cmdlineluser cmdlineluser added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Oct 21, 2024
coastalwhite added a commit to coastalwhite/polars that referenced this issue Dec 3, 2024
Fixes pola-rs#19336.

There was some unsoundness before when creating the frame that has now be
resolved.

This also moves pl.DataFrame.*_horizontal functions away from their own custom
implementation and towards using `pl.select(_ = pl.*_horizontal)`.
@c-peters c-peters added the accepted Ready for implementation label Dec 8, 2024
@c-peters c-peters moved this to Done in Backlog Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants