Skip to content

IntervalIndex level in MultiIndex does not work as expected #25298

Open
@pushkarnimkar

Description

@pushkarnimkar

I am trying to index data frame with a MultiIndex with constituent IntervalIndex

Example

ii = pd.IntervalIndex.from_arrays([1, 5, 2, 6, 3, 7], [4, 8, 5, 9, 6, 10])
mi = pd.MultiIndex.from_arrays([["aa", "aa", "bb", "bb", "cc", "cc"], ii])
data = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11, 12)]
df = pd.DataFrame(data, columns=['k', 'l'], index=mi)
df.loc[("bb", 3)]

Above code throws TypeError as follows:

TypeError: cannot do label indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [3] of <class 'int'>

I was expecting above to produce same result as:

df.loc[("bb")].loc[3]
# k    5
# l    6
# Name: (2, 5], dtype: int64

Is this a bug or I'm not using it properly? (newbie here)

Version Details:

python: Python 3.6.7 | packaged by conda-forge | (default, Nov 21 2018, 03:09:43)
pandas: '0.23.4'

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesIntervalInterval data typeMultiIndexNeeds TestsUnit test(s) needed to prevent regressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions