Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
phofl opened this issue Nov 13, 2020 · 0 comments · Fixed by #37830
Closed
3 tasks done

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

phofl opened this issue Nov 13, 2020 · 0 comments · Fixed by #37830
Milestone

Comments

@phofl
Copy link
Member

phofl commented Nov 13, 2020

  • 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

@phofl phofl added Bug Needs Triage Issue that has not been reviewed by a pandas team member MultiIndex labels Nov 13, 2020
@jreback jreback added this to the 1.2 milestone Nov 25, 2020
@jreback jreback removed the Needs Triage Issue that has not been reviewed by a pandas team member label Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants