Skip to content

ENH: The behavior of indexing on a MultiIndex with a nested sequence of labels is deprecated #49206

@MarkoM-5

Description

@MarkoM-5

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

Issue regarding future deprecation:

FutureWarning: The behavior of indexing on a MultiIndex with a nested sequence of labels is deprecated and will change in a future version. series.loc\[label, sequence] will raise if any members of 'sequence' or not present in the index's second level. To retain the old behavior, use series.index.isin(sequence, level=1)

Feature Description

Currently we use a one liner to filter a series with tuple including nested sequences. It works perfectly fine. But sometimes warning messages arise indicating that we have to use series.index.isin(). This method not only adds more lines to our code but also decreases our performance.

For example in our code we create our desired series using:

series = df_occupancy.loc[df_index, column_name]

where a snippet of df_occupancy is:
image

df_index = ([1, 2], slice(datetime.date(...10), None), slice(None, datetime...29), None), slice(datetime.time(...one, None))

column_name = free_capacity

Notably, the issue arises from the [1,2] in df_index where we try to select a weekday from the given weekdays in df_occupancy.

from here, we create series that is:
image

Essentially, the weekday column in df_occupancy is different wtr to a group or location etc. We also can not simply know what weekday will be in df_occupancy when using df_index to filter df_occupancy.

Essentially, the current state of .loc allows us to filter a Series without explicitly knowing exactly what is in the index, namely what weekdays we are searching for.

Alternative Solutions

We created an alterantive method using series.index.isin(sequence, level =1 ) and it is definitely less efficient and utilities more lines of code.

We would like to request Pandas: Please do not deprecate this in the future, or at least give an option that allows us to .loc the way it already is!!

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions