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

Panic on DataFrame.pivot when using common aggregate function on string data #17081

Closed
2 tasks done
jbarlow83 opened this issue Jun 20, 2024 · 2 comments · Fixed by #17090
Closed
2 tasks done

Panic on DataFrame.pivot when using common aggregate function on string data #17081

jbarlow83 opened this issue Jun 20, 2024 · 2 comments · Fixed by #17090
Assignees
Labels
A-panic Area: code that results in panic exceptions accepted Ready for implementation python Related to Python Polars test Related to the test suite

Comments

@jbarlow83
Copy link

jbarlow83 commented Jun 20, 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

df = pl.DataFrame(
    {
        "a": ['1', '2', '3'],
        "b": ['4', '5', '6'],
        "c": ['7', '8', '9'],
    }
)
df.pivot(index='a', columns='b', values='c', aggregate_function='min')

Log output

thread 'polars-24' panicked at crates/polars-core/src/series/iterator.rs:90:9:
assertion `left == right` failed: impl error
  left: 3
 right: 1

PanicException                            Traceback (most recent call last)
/tmp/ipykernel_216518/2344724553.py in ?()
----> 1 df2.pivot(index='a', columns='b', values='c', aggregate_function='max')

~/Documents/MARs/Scripts/.venv/lib/python3.11/site-packages/polars/_utils/deprecation.py in ?(*args, **kwargs)
    223         @wraps(function)
    224         def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
    225             if len(args) > num_allowed_args:
    226                 issue_deprecation_warning(msg, version=version)
--> 227             return function(*args, **kwargs)

~/Documents/MARs/Scripts/.venv/lib/python3.11/site-packages/polars/dataframe/frame.py in ?(self, values, index, columns, aggregate_function, maintain_order, sort_columns, separator)
   7767         else:
   7768             aggregate_expr = aggregate_function._pyexpr
   7769 
   7770         return self._from_pydf(
-> 7771             self._df.pivot_expr(
   7772                 index,
   7773                 columns,
   7774                 values,

PanicException: assertion `left == right` failed: impl error
  left: 3
 right: 1

Issue description

When attempting to pivot on string data, panics occur when an aggregate function is used on string inputs.

Expected behavior

Instead of panicking, raise an exception stating that aggregate functions like max/max are not capable of handling non-numeric data types, or something like that.

Note that somewhere around 0.20.20, aggregate functions worked on strings.

Installed versions

--------Version info---------
Polars:               0.20.31
Index type:           UInt32
Platform:             Linux-6.9.3-76060903-generic-x86_64-with-glibc2.35
Python:               3.11.9 (main, Apr  6 2024, 17:59:24) [GCC 11.4.0]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           0.3.2
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         1.5.8
numpy:                2.0.0
openpyxl:             3.1.4
pandas:               2.2.2
pyarrow:              16.1.0
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             0.8.2
xlsxwriter:           3.2.0
@jbarlow83 jbarlow83 added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jun 20, 2024
@MarcoGorelli MarcoGorelli added A-panic Area: code that results in panic exceptions and removed needs triage Awaiting prioritization by a maintainer labels Jun 20, 2024
@ritchie46
Copy link
Member

I cannot reproduce on main?

@MarcoGorelli
Copy link
Collaborator

it reproduces on 0.20.31, but is fixed in the pre-release. looks like it's "fixed itself"?

might be worth just adding a little test to make sure it doesn't regress

@MarcoGorelli MarcoGorelli added test Related to the test suite and removed bug Something isn't working labels Jun 20, 2024
ritchie46 added a commit that referenced this issue Jun 20, 2024
ritchie46 added a commit that referenced this issue Jun 20, 2024
@c-peters c-peters added the accepted Ready for implementation label Jun 24, 2024
@c-peters c-peters added this to Backlog Jun 24, 2024
@c-peters c-peters moved this to Done in Backlog Jun 24, 2024
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 accepted Ready for implementation python Related to Python Polars test Related to the test suite
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants