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

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"

@jreback jreback modified the milestone: 0.19.0, 0.19.1 Sep 27, 2016

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