Closed
Description
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"