-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix index locator cast bool key to float. #22357
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
machenity
commented
Aug 15, 2018
- closes index locators cast bool to float (and not to int) #19087
@machenity : Good start! We're going to need tests and a |
Codecov Report
@@ Coverage Diff @@
## master #22357 +/- ##
==========================================
+ Coverage 92.05% 92.05% +<.01%
==========================================
Files 169 169
Lines 50724 50733 +9
==========================================
+ Hits 46693 46702 +9
Misses 4031 4031
Continue to review full report at Codecov.
|
@gfyoung Do your 'tests' mean that i have to write new test case code or just be okay with those codecov test? |
I believe @gfyoung meant a test for your change. Will you come to the PyCon KR sprint tomorrow? |
@scari Yes, i will, but i have a tutorial before that. |
pandas/core/indexes/numeric.py
Outdated
@@ -403,7 +403,7 @@ def __contains__(self, other): | |||
@Appender(_index_shared_docs['get_loc']) | |||
def get_loc(self, key, method=None, tolerance=None): | |||
try: | |||
if np.all(np.isnan(key)): | |||
if np.all(np.isnan(key)) or isinstance(key, bool): |
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_bool here
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.
Does python have is_bool()
function?
I used isinstance()
to check if key is an instance of subclass of bool.
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.
Oh sorry, I found it.
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.
pandas has all of these functions, which we consistently use. thanks
doc/source/whatsnew/v0.24.0.txt
Outdated
@@ -653,6 +653,7 @@ Indexing | |||
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`) | |||
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`) | |||
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`) | |||
- ``Float64Index.get_loc`` now raises KeyError when boolean key passed. (:issue:`19087`) |
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.
Double back-ticks on KeyError.
lgtm. small change suggested by @gfyoung |
@gfyoung I edited it. Thank you for your suggestion. |
thanks @machenity |