-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Check types in Index.__contains__ (#22085) #22360
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
Changes from 6 commits
4ae2e60
b8f164e
004c855
c1409cb
f979733
a88497a
511060a
a5f2388
d61db2c
2aa3920
8384a3c
4eec1b4
6093091
20a6bd6
6e9f5a5
0b8217e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1949,7 +1949,11 @@ def __nonzero__(self): | |
def __contains__(self, key): | ||
hash(key) | ||
try: | ||
return key in self._engine | ||
if is_float(key) and is_integer_dtype(self.dtype) and\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use |
||
int(key) != key: | ||
return False | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need the else here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return key in self._engine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is ok in python code, but actually can you see if you can do this in the cython code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. But I'm not good at Cython now. I'd like to try it but it'll take time. |
||
except (OverflowError, TypeError, ValueError): | ||
return False | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2483,6 +2483,14 @@ def test_comparison_tzawareness_compat(self, op): | |
# TODO: implement _assert_tzawareness_compat for the reverse | ||
# comparison with the Series on the left-hand side | ||
|
||
def test_contains_with_float_val(self): | ||
# GH#22085 | ||
index = pd.Index([0, 1, 2, 3]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also add a Float index and test the same cases |
||
|
||
assert 1.1 not in index | ||
assert 1.0 in index | ||
assert 1 in index | ||
|
||
|
||
class TestIndexUtils(object): | ||
|
||
|
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.
something more along the line of
Bug in 'scalar in Index' if scalar is a float while the Index is of integer dtype.