Skip to content

Commit 668f0f7

Browse files
committed
Merge pull request #7068 from cpcloud/float64-index-bug
BUG: PEBKAC bug in Float64Index
2 parents 7fc7ad7 + 62bb43d commit 668f0f7

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ Bug Fixes
475475
caused possible color/class mismatch (:issue:`6956`)
476476
- Bug in ``radviz`` and ``andrews_curves`` where multiple values of 'color'
477477
were being passed to plotting method (:issue:`6956`)
478+
- Bug in ``Float64Index.isin()`` where containing ``nan`` s would make indices
479+
claim that they contained all the things (:issue:`7066`).
478480

479481
pandas 0.13.1
480482
-------------

pandas/core/index.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,8 @@ def isin(self, values):
20962096
"""
20972097
value_set = set(values)
20982098
return lib.ismember_nans(self._array_values(), value_set,
2099-
self._hasnans)
2099+
isnull(list(value_set)).any())
2100+
21002101

21012102
class MultiIndex(Index):
21022103

pandas/tests/test_index.py

+19
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,25 @@ def test_contains_not_nans(self):
913913
i = Float64Index([1.0, 2.0, np.nan])
914914
self.assertTrue(1.0 in i)
915915

916+
def test_doesnt_contain_all_the_things(self):
917+
i = Float64Index([np.nan])
918+
self.assertFalse(i.isin([0]).item())
919+
self.assertFalse(i.isin([1]).item())
920+
self.assertTrue(i.isin([np.nan]).item())
921+
922+
def test_nan_multiple_containment(self):
923+
i = Float64Index([1.0, np.nan])
924+
np.testing.assert_array_equal(i.isin([1.0]), np.array([True, False]))
925+
np.testing.assert_array_equal(i.isin([2.0, np.pi]),
926+
np.array([False, False]))
927+
np.testing.assert_array_equal(i.isin([np.nan]),
928+
np.array([False, True]))
929+
np.testing.assert_array_equal(i.isin([1.0, np.nan]),
930+
np.array([True, True]))
931+
i = Float64Index([1.0, 2.0])
932+
np.testing.assert_array_equal(i.isin([np.nan]),
933+
np.array([False, False]))
934+
916935

917936
class TestInt64Index(tm.TestCase):
918937
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)