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: failing MultiIndex.set_levels with inplace=True still modifies original index #13754

Closed
jorisvandenbossche opened this Issue Jul 22, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@jorisvandenbossche
Member

jorisvandenbossche commented Jul 22, 2016

Small example:

In [87]: df = pd.DataFrame(columns=pd.MultiIndex.from_product([['A','B'],['a','b']]))

Setting the levels with an incorrect levels (too short), fails (correctly of course):

In [92]: df.columns.set_levels(['c'], level=1)
...
ValueError: On level 1, label max (1) >= length of level  (1). NOTE: this index
is in an inconsistent state

When using inplace=True, this also gives the same error message, but the index is actually changed to this inconsistent state:

In [93]: df.columns.set_levels(['c'], level=1, inplace=True)
...
ValueError: On level 1, label max (1) >= length of level  (1). NOTE: this index
is in an inconsistent state

In [94]: df.columns
Out[94]:
MultiIndex(levels=[[u'A', u'B'], [u'c']],
           labels=[[0, 0, 1, 1], [0, 1, 0, 1]])

Just showing this df in the console did crash my session in the case above, in the example from #13741, it gave the error "IndexError: index 1 is out of bounds for axis 0 with size 1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment