Skip to content

Fix Inconsistent MultiIndex Sorting #21043

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

Merged
merged 7 commits into from
May 19, 2018
Merged

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented May 15, 2018

closes #20994
closes #20945
closes #21052

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

This is a pretty dark corner and I'll admit that I don't fully understand all of the elements in play. That said, the first problem I noticed with the first referenced issue was an errant conditional that was causing level=0 and level='foo' to go down two different branches, even if the name of the first level was in fact 'foo'.

After uncovering that, the subsequent ordering of the returned index then was incorrect regardless of the argument. I moved a monotonic sort around to fix this, though I feel like:

  • There may be a more general purpose solution to fix this AND
  • There may be more expressive tests to add here

Feedback appreciated

@codecov
Copy link

codecov bot commented May 15, 2018

Codecov Report

Merging #21043 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21043      +/-   ##
==========================================
- Coverage   91.82%   91.82%   -0.01%     
==========================================
  Files         153      153              
  Lines       49503    49503              
==========================================
- Hits        45458    45457       -1     
- Misses       4045     4046       +1
Flag Coverage Δ
#multiple 90.22% <100%> (-0.01%) ⬇️
#single 41.88% <33.33%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/frame.py 97.22% <100%> (ø) ⬆️
pandas/core/series.py 94.02% <100%> (ø) ⬆️
pandas/core/reshape/reshape.py 99.78% <0%> (-0.22%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3147a86...a10df10. Read the comment docs.

@WillAyd
Copy link
Member Author

WillAyd commented May 15, 2018

Just added a test and fix to cover Series as well, as we had another related issue pop up

cc @kdebrab

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels May 17, 2018
@jreback jreback added this to the 0.24.0 milestone May 17, 2018
@jreback
Copy link
Contributor

jreback commented May 17, 2018

lgtm. @toobaz if you'd have a quick look. merge if ok.

@jreback jreback merged commit bc37ea2 into pandas-dev:master May 19, 2018
@jreback
Copy link
Contributor

jreback commented May 19, 2018

thanks @WillAyd very nice!

@WillAyd WillAyd deleted the unstack-swap-bug branch June 2, 2018 18:42
@jorisvandenbossche
Copy link
Member

Does this need a whatsnew?

@WillAyd
Copy link
Member Author

WillAyd commented Jun 4, 2018

@jorisvandenbossche I can add one. Should I just open a separate PR for that?

@jorisvandenbossche
Copy link
Member

If you think it is needed (if there are user facing changes), then a new PR is perfect

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.24.0, 0.23.1 Jun 5, 2018
jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Jun 8, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jun 9, 2018
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
3 participants