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

pivot may still introduce duplicate column names (in a different way!) #14305

Closed
2 tasks done
MarcoGorelli opened this issue Feb 6, 2024 · 2 comments · Fixed by #14431
Closed
2 tasks done

pivot may still introduce duplicate column names (in a different way!) #14305

MarcoGorelli opened this issue Feb 6, 2024 · 2 comments · Fixed by #14431
Labels
bug Something isn't working P-high Priority: high 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

the duplicates never stop

In [6]: df = pl.DataFrame({'a': [1,3,2], 'c': ['a', 'a', 'a'], 'd':[7,8,9]})

In [7]: df.pivot(index='a', columns='c', values='d')
Out[7]:
shape: (3, 2)
┌─────┬─────┐
│ aa   │
│ ------ │
│ i64i64 │
╞═════╪═════╡
│ 17   │
│ 38   │
│ 29   │
└─────┴─────┘

Log output

No response

Issue description

if index is a column with the same name as one of the values in the columns column

Expected behavior

raise

Installed versions

In [4]: pl.show_versions()
--------Version info---------
Polars:               0.20.7
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:          3.0.0
connectorx:           <not installed>
deltalake:            <not installed>
fsspec:               2023.12.2
gevent:               <not installed>
hvplot:               0.9.1
matplotlib:           3.8.2
numpy:                1.26.3
openpyxl:             <not installed>
pandas:               2.2.0
pyarrow:              15.0.0
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           2.0.25
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@MarcoGorelli MarcoGorelli added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer P-high Priority: high and removed needs triage Awaiting prioritization by a maintainer labels Feb 6, 2024
@MarcoGorelli MarcoGorelli changed the title pivot may still introduce duplicates (in a different way!) pivot may still introduce duplicate column names (in a different way!) Feb 6, 2024
@ritchie46
Copy link
Member

Any idea of a naming strategy here?

@MarcoGorelli
Copy link
Collaborator Author

MarcoGorelli commented Feb 10, 2024

tidyr would just raise, and pandas doesn't consider duplicate column names to be a bug (!) (though pandas has an index anyway, so in this case it would just name the index 'a')

I'd suggest just raising

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-high Priority: high python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants