Skip to content

BUG/API: should MultiIndex with leading integer level fallback to positional? #33355

Closed
@jbrockmendel

Description

@jbrockmendel

idx = pd.Index(range(3))
dti = pd.date_range("2016-01-01", periods=2)
mi = pd.MultiIndex.from_product([idx, dti])

ser = pd.Series(range(len(mi))[::-1], index=mi)

>>> ser
0  2016-01-01    5
   2016-01-02    4
1  2016-01-01    3
   2016-01-02    2
2  2016-01-01    1
   2016-01-02    0
dtype: int64
>>> ser[3]
2

My intuition is that ser[3] should behave like indexing on just the first level of the MultIIndex:

ser2 = ser.droplevel(1)

>>> ser2
0    5
0    4
1    3
1    2
2    1
2    0
dtype: int64
>>> ser2[3]
KeyError: 3

Should we avoid the fallback-to-positional behavior in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions