Skip to content
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

BUG: Check types in Index.__contains__ (#22085) #22360

Closed
wants to merge 16 commits into from
Closed

BUG: Check types in Index.__contains__ (#22085) #22360

wants to merge 16 commits into from

Conversation

yeojin-dev
Copy link
Contributor

@yeojin-dev yeojin-dev commented Aug 15, 2018

I added is_float, is_integer_dtype in Index.__contains__.
If key is float and dtype of Index object is integer, return False.

@pep8speaks
Copy link

pep8speaks commented Aug 16, 2018

Hello @yeojin-dev! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on August 30, 2018 at 15:29 Hours UTC

@codecov
Copy link

codecov bot commented Aug 16, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@98e77e9). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #22360   +/-   ##
=========================================
  Coverage          ?   92.04%           
=========================================
  Files             ?      169           
  Lines             ?    50783           
  Branches          ?        0           
=========================================
  Hits              ?    46741           
  Misses            ?     4042           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.45% <ø> (?)
#single 42.22% <ø> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98e77e9...0b8217e. Read the comment docs.

@jreback
Copy link
Contributor

jreback commented Aug 16, 2018

note that this duplicates #22366

need tests & a whatsnew entry

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Aug 16, 2018
@yeojin-dev
Copy link
Contributor Author

@jreback Thank you for checking my PR. I added test and whatsnew. I hope these may help you. 😊

@@ -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`)
- Bug in :func:`Index.__contains__` that returns True just in case val is float and dtype is integer, because float casted to integer (:issue:`22085`)
Copy link
Contributor

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.

@@ -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\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use \ for line continuation, instead use parens

@@ -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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a Float index and test the same cases

@yeojin-dev
Copy link
Contributor Author

yeojin-dev commented Aug 17, 2018

@jreback I fixed them. Please check. 😊

@yeojin-dev
Copy link
Contributor Author

@jreback Could you please give me your feedback on my last commit?

@@ -658,6 +658,7 @@ Indexing
- 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`)
- Bug in `scalar in Index` if scalar is a float while the Index is of integer dtype (:issue:`22085`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use double-backticks on the Index (2nd use in sentence)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (is_float(key) and is_integer_dtype(self.dtype) and
int(key) != key):
return False
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need the else here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

int(key) != key):
return False
else:
return key in self._engine
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@yeojin-dev
Copy link
Contributor Author

@jreback My new commits has just passed a test in my Mac. But can't here, GitHub.

See the logs below.

  1. Travis
ImportError: libgfortran.so.1: cannot open shared object file: No such file or directory
The command "ci/install_travis.sh" failed and exited with 1 during .
  1. Circle
ImportError: libgfortran.so.1: cannot open shared object file: No such file or directory

I guess these errors are not caused by my commits. Please check.

@yeojin-dev
Copy link
Contributor Author

@jreback I wrote the code in Cython. But my code has just passed the test, can't pass here. I can't understand... 😢

@jreback
Copy link
Contributor

jreback commented Sep 4, 2018

can you rebase

@yeojin-dev yeojin-dev closed this Sep 5, 2018
@yeojin-dev yeojin-dev deleted the fix-22085 branch September 5, 2018 06:13
@yeojin-dev yeojin-dev restored the fix-22085 branch September 5, 2018 06:15
@yeojin-dev
Copy link
Contributor Author

@jreback Sorry. I deleted the branch while rebasing it. Please see my new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checking that a pandas.Series.index contains a value
3 participants