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.pivot returns incorrect results when (single) index is struct #14101

Closed
2 tasks done
MarcoGorelli opened this issue Jan 30, 2024 · 2 comments · Fixed by #14308
Closed
2 tasks done

DataFrame.pivot returns incorrect results when (single) index is struct #14101

MarcoGorelli opened this issue Jan 30, 2024 · 2 comments · Fixed by #14308
Assignees
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@MarcoGorelli
Copy link
Collaborator

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

In [1]: df = pl.DataFrame({'a': [1, 2], 'b': [{'a': 1}, {'a': 1}], 'c': ['x', 'y']})

In [2]: df
Out[2]:
shape: (2, 3)
┌─────┬───────────┬─────┐
│ abc   │
│ --------- │
│ i64struct[1] ┆ str │
╞═════╪═══════════╪═════╡
│ 1   ┆ {1}       ┆ x   │
│ 2   ┆ {1}       ┆ y   │
└─────┴───────────┴─────┘

In [3]: df.pivot(index='b', values='a', columns='c')
Out[3]:
shape: (2, 3)
┌───────────┬──────┬──────┐
│ bxy    │
│ ---------  │
│ struct[1] ┆ i64i64  │
╞═══════════╪══════╪══════╡
│ {null}    ┆ 1null │
│ {null}    ┆ null2    │
└───────────┴──────┴──────┘

Log output

No response

Issue description

here's the cause (and solution!) #14048 (comment)

Expected behavior

I think it should be

shape: (1, 3)
┌───────────┬──────┬──────┐
│ b         ┆ x    ┆ y    │
│ ---       ┆ ---  ┆ ---  │
│ struct[1] ┆ i64  ┆ i64  │
╞═══════════╪══════╪══════╡
│ {1}       ┆ 1    ┆ 2    │
└───────────┴──────┴──────┘

Installed versions

--------Version info---------
Polars:               0.20.5
Index type:           UInt32
Platform:             Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python:               3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fsspec:               2023.12.2
gevent:               <not installed>
hvplot:               0.9.1
matplotlib:           <not installed>
numpy:                1.26.3
openpyxl:             <not installed>
pandas:               1.3.4
pyarrow:              15.0.0
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           2.0.25
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@ritchie46
Copy link
Member

Is this still the case?

@MarcoGorelli
Copy link
Collaborator Author

yes - got a few things on my plate this week but will try to get to it

@MarcoGorelli MarcoGorelli added P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Jan 31, 2024
@MarcoGorelli MarcoGorelli self-assigned this Jan 31, 2024
@MarcoGorelli MarcoGorelli changed the title DataFrame.pivot returns incorrect results when index is struct DataFrame.pivot returns incorrect results when (single) index is struct Feb 6, 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 P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants