-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.stack sometimes sorting the resulting index #53825
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
Conversation
…into stack_sort_bug � Conflicts: � doc/source/whatsnew/v2.1.0.rst
@@ -498,7 +498,8 @@ Reshaping | |||
- Bug in :meth:`DataFrame.idxmin` and :meth:`DataFrame.idxmax`, where the axis dtype would be lost for empty frames (:issue:`53265`) | |||
- Bug in :meth:`DataFrame.merge` not merging correctly when having ``MultiIndex`` with single level (:issue:`52331`) | |||
- Bug in :meth:`DataFrame.stack` losing extension dtypes when columns is a :class:`MultiIndex` and frame contains mixed dtypes (:issue:`45740`) | |||
- Bug in :meth:`DataFrame.stack` sorting columns lexicographically (:issue:`53786`) | |||
- Bug in :meth:`DataFrame.stack` sorting columns lexicographically in rare cases (:issue:`53786`) | |||
- Bug in :meth:`DataFrame.stack` sorting index lexicographically in rare cases (:issue:`53824`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tons of tests for stacking not sorting the order; only one of them is impacted by this bug. I haven't been able to figure out a way to describe the circumstances this happens under.
… into stack_sort_bug_2 # Conflicts: # doc/source/whatsnew/v2.1.0.rst # pandas/core/reshape/reshape.py
@mroeschke - this removes all uses of On the other hand, #53282 does not modify the sorting of the values (values here being the levels + codes combination), but rather just the sorting of the levels (the codes are then also adjusted so the values come out the same). This PR essentially only implements |
Hmm it would be nice for API consistency for |
No - it's not. But I was leaning the other way: remove
In general I advocate for not having arguments when it's just an additional call, but perhaps the perf benefit is worth it here? Somewhat like unstack, we can implement |
Yeah I agree with not having arguments when its an additional call, additionally I think the |
Nice thanks @rhshadrach |
…v#53825) * BUG: DataFrame.stack with sort=True and unsorted MultiIndex levels * revert ignoring warnings * BUG: DataFrame.stack sorting columns * whatsnew * Docstring fixup * Merge cleanup * WIP * BUG: DataFrame.stack sometimes sorting the resulting index * mypy fixups * Remove sort argument from DataFrame.stack
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.