Skip to content

sort_index doesn't sort MultiIndex when .loc[] referred to non-existent label on other axis #12261

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

Closed
toobaz opened this issue Feb 8, 2016 · 3 comments · Fixed by #30674
Closed
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@toobaz
Copy link
Member

toobaz commented Feb 8, 2016

In [2]: df = pd.DataFrame(0, columns=[], index=pd.MultiIndex.from_product([[], []]))

In [3]: df.loc['b', '2'] = 1

In [4]: df.loc['a', '3'] = 1

In [5]: df.sort_index()
Out[5]: 
      2    3
b   1.0  NaN
a   NaN  1.0

In [6]: df.sort_index().index.is_monotonic
Out[6]: False

Am I missing anything obvious?!
(Notice that this is not related to any of the two axes being initialized as empty)

@toobaz toobaz changed the title sort_index doesn't sort MultiIndex when .loc[] was referred to non-existent label on other axis sort_index doesn't sort MultiIndex when .loc[] referred to non-existent label on other axis Feb 8, 2016
@jreback
Copy link
Contributor

jreback commented Feb 10, 2016

I guess this is a bug. not really sure whats going on.

@jreback jreback added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Difficulty Intermediate labels Feb 10, 2016
@jreback jreback added this to the Next Major Release milestone Feb 10, 2016
@mroeschke
Copy link
Member

Looks fixed on master. Guess this could use a test

In [105]: df.sort_index().index.is_monotonic
Out[105]: True

In [107]: pd.__version__
Out[107]: '0.26.0.dev0+555.gf7d162b18'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Difficulty Intermediate Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Oct 14, 2019
@alimcmaster1
Copy link
Member

@ainsleyto is currently having a look! - thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
4 participants