-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Cleaner exception when .iloc
called with non-integer list
#25759
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
.iloc
called with non-integer list.iloc
called with non-integer list
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.
Needs a new test to catch that this error message is raised.
Codecov Report
@@ Coverage Diff @@
## master #25759 +/- ##
==========================================
- Coverage 91.25% 91.24% -0.01%
==========================================
Files 172 172
Lines 52977 52979 +2
==========================================
+ Hits 48342 48343 +1
- Misses 4635 4636 +1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25759 +/- ##
==========================================
+ Coverage 91.26% 91.26% +<.01%
==========================================
Files 172 172
Lines 52965 52967 +2
==========================================
+ Hits 48337 48339 +2
Misses 4628 4628
Continue to review full report at Codecov.
|
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 @mroeschke
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.
One small whatsnew change otherwise looks good to me.
pandas/core/indexing.py
Outdated
@@ -2079,6 +2079,10 @@ def _validate_key(self, key, axis): | |||
arr = np.array(key) | |||
len_axis = len(self.obj._get_axis(axis)) | |||
|
|||
if not np.issubdtype(arr.dtype, np.number): |
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.
use is_integer_dtype
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.
This will cause a new exception when an array of float values is passed to .iloc
. Currently float values are allowed and the array is cast to integer dtype. This will cause some regression.
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.
then you need to thread this in the appropriate place
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.
alt you could check is_numeric_dtype
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.
Alright I tried to reorganize it a bit, let me know if I misunderstood what you meant.
also merge master |
lgtm. @mroeschke over to you |
thanks @kykosic |
git diff upstream/master -u -- "*.py" | flake8 --diff
Issue #25753 was raised requesting more verbose error messages when calling
loc
andiloc
with mixed dtype arguments. In this pull request, I've added a new error message when callingiloc
with a non-numeric dtype list-like object.This fixes numpy ultimately raising an ambiguous exception when, for example, calling
.iloc
with a list of string column names:However, the current exception when calling
.loc
with integer column names when the column names are actually strings I feel is already accurate: