-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Open
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesMultiIndex
Description
-
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.
Code Sample, a copy-pastable example
df = pd.DataFrame({("z","a"): [1, 2, 3], ("z","b"):[4, 5, 6]})
df.loc[pd.IndexSlice[:, pd.IndexSlice["z", ["a", "b", "c"]]]] # works: DataFrame with columns 'a' and 'b'.
df = pd.DataFrame({("a"): [1, 2, 3], ("b"):[4, 5, 6]})
df.loc[pd.IndexSlice[:, pd.IndexSlice[["a", "b", "c"]]]] # KeyError: missing label 'c'
Problem description
Should this behaviour be consistent?
A recent decision to move to KeyError: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike
Expected Output
Both return KeyError?
This can be linked to #32125 also.
Metadata
Metadata
Assignees
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesMultiIndex