'Issue when slicing a pandas MultiIndex containing tuples

I found a weird behaviour when slicing on multiindex where the index is a tuple

tmp=pd.Series(0,index=pd.MultiIndex.from_tuples([
   (('a',),),
   (('b',),),
   (('c','cc'),),
   (('d','dd'),),
                          ]))

print(tmp.reindex(tmp.index[1:]))

yields the following results

(b,)       0.0
(c, cc)    NaN
(d, dd)    NaN

Am I using the multiIndex incorrectly or is it a bug? (pandas version='1.1.0')



Solution 1:[1]

Your code works well with a recent version of Pandas.

Output:

# pd.__version__: '1.4.1'
>>> tmp.reindex(tmp.index[1:])
(b,)       0
(c, cc)    0
(d, dd)    0
dtype: int64

Is it what you expect?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien