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

BUG: unstack with sort=False scrambles data #58991

Closed
2 of 3 tasks
mishavanbeek opened this issue Jun 12, 2024 · 3 comments
Closed
2 of 3 tasks

BUG: unstack with sort=False scrambles data #58991

mishavanbeek opened this issue Jun 12, 2024 · 3 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@mishavanbeek
Copy link

mishavanbeek commented Jun 12, 2024

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

assert pd.__version__ == "2.2.2"

df = pd.DataFrame(
    {
        "index1": [2, 1],
        "index2": [2, 1],
        "index3": [2, 1],
        "value": [2, 1],
    },
)
df = df.set_index(["index1", "index2", "index3"])


df.unstack(("index2", "index1"), sort=False)

Issue Description

When using triple indices and unstacking two, the data is mapped to the wrong index value when using sort=False. In the example the data should be on the diagonal.

Expected Behavior

The output with sort=True seems valid, but with the unsorted index.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.6.final.0
python-bits : 64
OS : Darwin
OS-release : 23.4.0
Version : Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:54 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6031
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 70.0.0
pip : 24.0
Cython : None
pytest : 8.2.2
hypothesis : None
...
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@mishavanbeek mishavanbeek added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 12, 2024
@rhshadrach
Copy link
Member

Thanks for the report. You've checked the box that you've confirmed this bug exists on the main branch of pandas. Can you double check you see this on main?

@rhshadrach rhshadrach added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 13, 2024
@mishavanbeek
Copy link
Author

mishavanbeek commented Jun 13, 2024

Apologies, I must have messed something up with poetry in installing main. It indeed looks like this was fixed with #56357, which somehow didn't pop up in my search.

@rhshadrach
Copy link
Member

Thanks @mishavanbeek - closing.

@rhshadrach rhshadrach added Duplicate Report Duplicate issue or pull request and removed Needs Info Clarification about behavior needed to assess issue labels Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants