Skip to content

ERR: improve error message for invalid indexer #31769

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

Merged

Conversation

jorisvandenbossche
Copy link
Member

Convert the long repr of the Index into just the name. So something like

cannot do slice indexing on <class 'pandas.core.indexes.datetimes.DatetimeIndex'> with these indexers [key] of <class 'float'>

becomes

cannot do slice indexing on DatetimeIndex with these indexers [key] of type float"

@jorisvandenbossche jorisvandenbossche added Indexing Related to indexing on series/frames, not to indexes themselves Error Reporting Incorrect or improved errors from pandas labels Feb 7, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1 milestone Feb 7, 2020
self._validate_indexer("slice", key.step, "iloc")
self._validate_indexer("positional", key.start, "iloc")
self._validate_indexer("positional", key.stop, "iloc")
self._validate_indexer("positional", key.step, "iloc")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is for iloc, changing to positional (otherwise you can get confusing error message as "cannot do slice indexing on FloatIndex with indexer of type float" (which for label-based slice indexing would of course be totally fine)

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jorisvandenbossche jorisvandenbossche merged commit ca84bd0 into pandas-dev:master Feb 8, 2020
@jorisvandenbossche jorisvandenbossche deleted the indexing-error-msg branch February 8, 2020 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants