From 59110fd1d96fa33914195e91a182ac903d02f902 Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Wed, 7 May 2014 18:09:26 -0400 Subject: [PATCH 1/2] BUG: PEBKAC bug in Float64Index --- doc/source/release.rst | 2 ++ pandas/core/index.py | 3 ++- pandas/tests/test_index.py | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index b5a11091779ec..728dddbe8b979 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -475,6 +475,8 @@ Bug Fixes caused possible color/class mismatch (:issue:`6956`) - Bug in ``radviz`` and ``andrews_curves`` where multiple values of 'color' were being passed to plotting method (:issue:`6956`) +- Bug in ``Float64Index.isin()`` where containing ``nan`` s would make indices + claim that they contained all the things (:issue:`7066`). pandas 0.13.1 ------------- diff --git a/pandas/core/index.py b/pandas/core/index.py index ff6ee79bf24e4..c3619b992028d 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -2096,7 +2096,8 @@ def isin(self, values): """ value_set = set(values) return lib.ismember_nans(self._array_values(), value_set, - self._hasnans) + isnull(list(value_set)).any()) + class MultiIndex(Index): diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 206c85124e122..90638d9ed728a 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -913,6 +913,12 @@ def test_contains_not_nans(self): i = Float64Index([1.0, 2.0, np.nan]) self.assertTrue(1.0 in i) + def test_doesnt_contain_all_the_things(self): + i = Float64Index([np.nan]) + self.assertFalse(i.isin([0]).item()) + self.assertFalse(i.isin([1]).item()) + self.assertTrue(i.isin([np.nan]).item()) + class TestInt64Index(tm.TestCase): _multiprocess_can_split_ = True From 62bb43d063f951cec27dc91813d55b7566967be8 Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Wed, 7 May 2014 23:06:39 -0400 Subject: [PATCH 2/2] TST: add test for multiple element Float64Index containment --- pandas/tests/test_index.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 90638d9ed728a..dafbfd07ca51d 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -919,6 +919,19 @@ def test_doesnt_contain_all_the_things(self): self.assertFalse(i.isin([1]).item()) self.assertTrue(i.isin([np.nan]).item()) + def test_nan_multiple_containment(self): + i = Float64Index([1.0, np.nan]) + np.testing.assert_array_equal(i.isin([1.0]), np.array([True, False])) + np.testing.assert_array_equal(i.isin([2.0, np.pi]), + np.array([False, False])) + np.testing.assert_array_equal(i.isin([np.nan]), + np.array([False, True])) + np.testing.assert_array_equal(i.isin([1.0, np.nan]), + np.array([True, True])) + i = Float64Index([1.0, 2.0]) + np.testing.assert_array_equal(i.isin([np.nan]), + np.array([False, False])) + class TestInt64Index(tm.TestCase): _multiprocess_can_split_ = True