Closed
Description
We treat list indexers differently from array-like indexers:
ser = pd.Series(["A", "B"])
key = pd.Series(["C"])
>>> ser[key]
C NaN
dtype: object
>>> ser[pd.Index(key)]
C NaN
dtype: object
>>> ser[np.array(key)]
C NaN
dtype: object
>>> ser[list(key)]
Traceback (most recent call last):
[...]
File "/Users/bmendel/Desktop/pd/pandas/pandas/core/indexing.py", line 1312, in _validate_read_indexer
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index(['C'], dtype='object')] are in the [index]"
Also inconsistent because ser.loc[key]
raises for all 4 cases.
Is there a compelling reason for this? I tried making all of these behave like the list case and only one test broke (that test being the example above). The test was added in #5880.