Skip to content

API: Series[index_with_no_matches] vs Series[list_with_no_matches] #33642

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
jbrockmendel opened this issue Apr 18, 2020 · 0 comments · Fixed by #33646
Closed

API: Series[index_with_no_matches] vs Series[list_with_no_matches] #33642

jbrockmendel opened this issue Apr 18, 2020 · 0 comments · Fixed by #33646
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jbrockmendel
Copy link
Member

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.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 18, 2020
@jreback jreback added this to the 1.1 milestone Apr 19, 2020
@jreback 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants