Skip to content
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

API/BUG: raise only KeyError failed on geitem/loc lookups #31867

Merged
merged 8 commits into from
Feb 27, 2020

Conversation

jbrockmendel
Copy link
Member

ATM we raise a mix of KeyError and TypeError.

I'm in the process of going through the Indexing issues will see what else this closes.

@jbrockmendel
Copy link
Member Author

As a follow-up to this, it turns out we can entirely rip out _convert_scalar_indexer, which will be really nice

@WillAyd
Copy link
Member

WillAyd commented Feb 11, 2020

I think this makes sense though may break some user code catching a TypeError, so if others agree at least worth a note maybe a deprecation

@WillAyd WillAyd added the Error Reporting Incorrect or improved errors from pandas label Feb 11, 2020
@jorisvandenbossche
Copy link
Member

I don't think it is possible to do with a deprecation? Or how would people be able to avoid the deprecation?
We could maybe also have a custom exception class that inherits both ..

Apart of changing the API; I assume that those different errors where there initially to provide a more useful error message to the user (instead of just "KeyError: some_value") ?

@jreback
Copy link
Contributor

jreback commented Feb 17, 2020

ok I think this is reasonable, e.g. this highlites the difference between indexing a list for example with a non-integer (raises TypeError) and a dict with anything (raises KeyError). consistency is good.

As far as user impact; this is a change, but likely does not affect very many downstream users (who are likely catching both TypeError and KeyError).

would be ok with simply changing this (to raise KeyError), unless other objections.

@jbrockmendel jbrockmendel changed the title API/POC: raise only KeyError failed on geitem/loc lookups API/BUG: raise only KeyError failed on geitem/loc lookups Feb 19, 2020
@jbrockmendel jbrockmendel added the Indexing Related to indexing on series/frames, not to indexes themselves label Feb 19, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you add a whatsnew section in api-breaking. highlite what things changed as far as exception raised (be as specific as you can for the examples)

@jreback jreback added this to the 1.1 milestone Feb 23, 2020
@jreback
Copy link
Contributor

jreback commented Feb 23, 2020

this is a good change, any objections @jorisvandenbossche

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.

I guess this was originally inspired by Python getitem semantics?

https://docs.python.org/3/reference/datamodel.html#object.__getitem__

In any case probably tenuous on our end, so lgtm

@WillAyd WillAyd merged commit 5fa9860 into pandas-dev:master Feb 27, 2020
@WillAyd
Copy link
Member

WillAyd commented Feb 27, 2020

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the keyerror branch February 28, 2020 00:11
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this pull request Feb 28, 2020
WillAyd pushed a commit that referenced this pull request Feb 29, 2020
roberthdevries pushed a commit to roberthdevries/pandas that referenced this pull request Mar 2, 2020
roberthdevries pushed a commit to roberthdevries/pandas that referenced this pull request Mar 2, 2020
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.

Inconsistent error where looking for label of wrong type
4 participants