Open
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.