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..dafbfd07ca51d 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -913,6 +913,25 @@ 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()) + + 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