-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API/BUG: make .at raise same exceptions as .loc #31724
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
Conversation
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -63,7 +63,8 @@ Backwards incompatible API changes | |||
- :meth:`DataFrameGroupby.mean` and :meth:`SeriesGroupby.mean` (and similarly for :meth:`~DataFrameGroupby.median`, :meth:`~DataFrameGroupby.std`` and :meth:`~DataFrameGroupby.var``) | |||
now raise a ``TypeError`` if a not-accepted keyword argument is passed into it. | |||
Previously a ``UnsupportedFunctionCall`` was raised (``AssertionError`` if ``min_count`` passed into :meth:`~DataFrameGroupby.median``) (:issue:`31485`) | |||
|
|||
- :meth:`DataFrame.at` and :meth:`Series.at` will raise a ``TypeError`` instead of a ``ValueError`` if an incompatible key is passed, matching the behavior of ``.loc[]`` (:issue:`31722`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should mention the KeyError
here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check some timings for at
? (as this is supposed to be the fast one)
How does this indirectly also address #31683 ? And if it does, shouldn't there be tests involving categorical / a whatsnew?
msg = ( | ||
"At based indexing on an non-integer index can only have " | ||
"non-integer indexers" | ||
"cannot do label indexing on <class 'pandas.core.indexes.base.Index'> " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to say that I found the previous error message more readable ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally agree, that suggests we should improve the existing messages for "loc"
Yah we take a hit
We might get some of that back from #31709. |
With this in place, all the places from which index.get_value are called are preceeded by maybe_cast_scalar_indexer (except one in which the key is a tuple). That makes the call inside CategoricalIndex.get_value unnecessary, which addresses the motivating issue for #31683. The "indexing on CategoricalIndex is hard" problem is still a problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consistency is a huge + here, makes the code much better.
I am not sure if @WillAyd or @jorisvandenbossche have comments, but lgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. parametrization will be a nice follow on
thanks @jbrockmendel |
@jreback maybe you didn't notice, but this time I had a "request changes" open, as you asked previous time to indicate that you shouldn't merge without me having the chance to answer back. |
@jbrockmendel can you do a follow up with:
|
Looking back at it, it's actually mainly the long fully qualified class name that is annoying, so that is an easy fix -> #31769 |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
This also (very) indirectly addresses #31683 which in turn will let us get rid of
CategoricalIndex.get_value
altogether.