-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
fixes #22085 (int type pandas.series.index contains float type key bug) #22366
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
Codecov Report
@@ Coverage Diff @@
## master #22366 +/- ##
==========================================
- Coverage 92.05% 92.05% -0.01%
==========================================
Files 169 169
Lines 50709 50712 +3
==========================================
+ Hits 46679 46681 +2
- Misses 4030 4031 +1
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.
tests and pls add a whatsnew entry for 0.24
pandas/core/indexes/base.py
Outdated
@@ -1949,6 +1949,9 @@ def __nonzero__(self): | |||
def __contains__(self, key): | |||
hash(key) | |||
try: | |||
if type(key) == float and self.dtype == int: |
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_float(key) and is_integer_dtype(self.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.
I'm sorry, I'm very new to this. But could you please tell me what to add to whatsnew,
note that this duplicates #22360 |
pandas/core/indexes/base.py
Outdated
@@ -1949,6 +1949,9 @@ def __nonzero__(self): | |||
def __contains__(self, key): | |||
hash(key) | |||
try: | |||
if is_float(key) and is_integer_dtype(self.dtype): | |||
if key != int(key): | |||
return False |
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 would put this outside of the try/except block
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.
done
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.
@jorisvandenbossche I think it can't pass the test!
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.
So it fails when key is NaN ?
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 think so. The block is needed.
Hello @a1shadows! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 16, 2018 at 11:59 Hours UTC |
duplicate PR |
git diff upstream/master -u -- "*.py" | flake8 --diff
checks for type using is_float, is_integer_dtype and if key is a float that does not resolve to an equivalent int and Index is int, returns false.