Skip to content

BUG: MultiIndex.drop does not raise if labels are partially found #37820

Closed
@phofl

Description

@phofl
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

mi = MultiIndex.from_tuples([(1, 2), (2, 2), (3, 2)])
mi.drop([1, 4], level=0) # does not raise
mi.drop(4, level=0) # raises

Problem description

The docs say

Raises

    KeyError

        If not all of the labels are found in the selected axis

I think both statements should raise KeyError
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.drop.html

Expected Output

Both are raising KeyError: 'labels [4] not found in level'

For regular Indexes this holds True

index = Index([1, 2])
index.drop([1, 3]) # Raises

Output of pd.show_versions()

master

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions