Skip to content

BUG: Slicing of Index with strings does not raise anymore when keys are not in Index #37810

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
phofl opened this issue Nov 13, 2020 · 5 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves Needs Discussion Requires discussion from core team before further action

Comments

@phofl
Copy link
Member

phofl commented Nov 13, 2020

The following

df2 = pd.DataFrame({"A": [1, 2, 3]}, index=['a', 'c', 'b'])
df2.loc['d':'e']

Should raise a KeyError. This worked in the past (see #18531) but does not anymore. Question is if we should raise in slice_locs if start and end are equal or if we should do this after calling the function.

cc @jreback

@phofl phofl added Bug Needs Triage Issue that has not been reviewed by a pandas team member Indexing Related to indexing on series/frames, not to indexes themselves Needs Discussion Requires discussion from core team before further action and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 13, 2020
@phofl phofl added the Error Reporting Incorrect or improved errors from pandas label Nov 13, 2020
@jorisvandenbossche
Copy link
Member

This still raises a KeyError for me. With what version do you see something else? And can you show the output?

@phofl
Copy link
Member Author

phofl commented Nov 13, 2020

Sorry, i applied the loc to the DatetimeIndex, which did not raise on master (as expected). Mixed this up... You are right this still raises

@phofl phofl closed this as completed Nov 13, 2020
@phofl phofl added this to the No action milestone Nov 13, 2020
@phofl phofl reopened this Nov 13, 2020
@phofl
Copy link
Member Author

phofl commented Nov 13, 2020

cc @jorisvandenbossche

Hm used the wrong example. The above raises, but when the index is monotonic, it does not raise.

df2 = pd.DataFrame({"A": [1, 2, 3]}, index=['a', 'b', 'c'])
df2.loc['d':'e']

This does not raise for me on master

@phofl phofl removed this from the No action milestone Nov 13, 2020
@jorisvandenbossche
Copy link
Member

As far as I know, that is the expected result, because it is a monotonic index, the exact labels in the slice don't need to be present in the index

@phofl
Copy link
Member Author

phofl commented Nov 13, 2020

Ah ok, did not know that. Then closing this again

@phofl phofl closed this as completed Nov 13, 2020
@phofl phofl added this to the No action milestone Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

2 participants