You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
jreback
added
Indexing
Related to indexing on series/frames, not to indexes themselves
and removed
Needs Triage
Issue that has not been reviewed by a pandas team member
labels
Apr 19, 2020
We treat list indexers differently from array-like indexers:
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.
The text was updated successfully, but these errors were encountered: