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

DataFrame.sort() raises PanicException: arg_sort operation not supported for dtype struct[1] #7777

Closed
2 tasks done
cmdlineluser opened this issue Mar 25, 2023 · 1 comment · Fixed by #7822
Closed
2 tasks done
Assignees
Labels
bug Something isn't working python Related to Python Polars

Comments

@cmdlineluser
Copy link
Contributor

cmdlineluser commented Mar 25, 2023

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

Using df.sort() with a struct column raises an error pointing to:

https://github.com/pola-rs/polars/blob/master/polars/polars-core/src/series/series_trait.rs#L361-L363

Expr.sort was added for struct in #7021 - it seems like it should be possible in df.sort too?

Edit: It seems it's not specific to struct - it happens with lists too.

Thanks all.

Reproducible example

import polars as pl

df = pl.Series([{"a": 300}, {"a": 20}, {"a": 55}]).to_frame("st").with_row_count()

# shape: (3, 2)
# ┌────────┬───────────┐
# │ row_nr ┆ st        │
# │ ---    ┆ ---       │
# │ u32    ┆ struct[1] │
# ╞════════╪═══════════╡
# │ 0      ┆ {300}     │
# │ 1      ┆ {20}      │
# │ 2      ┆ {55}      │
# └────────┴───────────┘


df.with_columns(pl.col("st").sort())

# shape: (3, 2)
# ┌────────┬───────────┐
# │ row_nr ┆ st        │
# │ ---    ┆ ---       │
# │ u32    ┆ struct[1] │
# ╞════════╪═══════════╡
# │ 0      ┆ {20}      │
# │ 1      ┆ {55}      │
# │ 2      ┆ {300}     │
# └────────┴───────────┘

df.sort("st")

#   thread '<unnamed>' panicked at 
#      '`arg_sort` operation not supported for dtype `struct[1]`',
#      polars/polars/polars-core/src/series/series_trait.rs:362:9

Expected behavior

# shape: (3, 2)
# ┌────────┬───────────┐
# │ row_nr ┆ st        │
# │ ---    ┆ ---       │
# │ u32    ┆ struct[1] │
# ╞════════╪═══════════╡
# │ 1      ┆ {20}      │
# │ 2      ┆ {55}      │
# │ 0      ┆ {300}     │
# └────────┴───────────┘

Installed versions

---Version info---
Polars: 0.16.15
Index type: UInt32
Python: 3.10.9 (main, Jan 14 2023, 16:56:26)
---Optional dependencies---
numpy: 1.23.5
pandas: 1.5.3
pyarrow: 9.0.0
connectorx: <not installed>
deltalake: <not installed>
fsspec: 2022.8.2
matplotlib: 3.5.1
xlsx2csv: 0.8
xlsxwriter: 3.0.8
@cmdlineluser cmdlineluser added bug Something isn't working python Related to Python Polars labels Mar 25, 2023
@ritchie46
Copy link
Member

Yes, we should add that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants