Skip to content

Commit 4bb6b2c

Browse files
committed
COMPAT: when "nan is nan" is not consistent across implementations
1 parent 5f43b0d commit 4bb6b2c

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pandas/tests/indexes/test_base.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas.tests.indexes.common import Base
1010

1111
from pandas.compat import (range, lrange, lzip, u,
12-
text_type, zip, PY3, PY36)
12+
text_type, zip, PY3, PY36, PYPY)
1313
import operator
1414
import numpy as np
1515

@@ -1360,13 +1360,21 @@ def test_isin(self):
13601360
assert len(result) == 0
13611361
assert result.dtype == np.bool_
13621362

1363-
def test_isin_nan(self):
1363+
@pytest.mark.skipif(PYPY, reason="np.nan is float('nan') on PyPy")
1364+
def test_isin_nan_not_pypy(self):
1365+
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([float('nan')]),
1366+
np.array([False, False]))
1367+
1368+
@pytest.mark.skipif(not PYPY, reason="np.nan is float('nan') on PyPy")
1369+
def test_isin_nan_pypy(self):
1370+
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([float('nan')]),
1371+
np.array([False, True]))
1372+
1373+
def test_isin_nan_common(self):
13641374
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([np.nan]),
13651375
np.array([False, True]))
13661376
tm.assert_numpy_array_equal(Index(['a', pd.NaT]).isin([pd.NaT]),
13671377
np.array([False, True]))
1368-
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([float('nan')]),
1369-
np.array([False, False]))
13701378
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([pd.NaT]),
13711379
np.array([False, False]))
13721380

pandas/tests/indexes/test_multi.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from pandas import (CategoricalIndex, DataFrame, Index, MultiIndex,
1616
compat, date_range, period_range)
17-
from pandas.compat import PY3, long, lrange, lzip, range, u
17+
from pandas.compat import PY3, long, lrange, lzip, range, u, PYPY
1818
from pandas.errors import PerformanceWarning, UnsortedIndexError
1919
from pandas.core.indexes.base import InvalidIndexError
2020
from pandas._libs import lib
@@ -2574,13 +2574,22 @@ def test_isin(self):
25742574
assert len(result) == 0
25752575
assert result.dtype == np.bool_
25762576

2577-
def test_isin_nan(self):
2577+
@pytest.mark.skipif(PYPY, reason="tuples cmp recursively on PyPy")
2578+
def test_isin_nan_not_pypy(self):
25782579
idx = MultiIndex.from_arrays([['foo', 'bar'], [1.0, np.nan]])
25792580
tm.assert_numpy_array_equal(idx.isin([('bar', np.nan)]),
25802581
np.array([False, False]))
25812582
tm.assert_numpy_array_equal(idx.isin([('bar', float('nan'))]),
25822583
np.array([False, False]))
25832584

2585+
@pytest.mark.skipif(not PYPY, reason="tuples cmp recursively on PyPy")
2586+
def test_isin_nan_pypy(self):
2587+
idx = MultiIndex.from_arrays([['foo', 'bar'], [1.0, np.nan]])
2588+
tm.assert_numpy_array_equal(idx.isin([('bar', np.nan)]),
2589+
np.array([False, True]))
2590+
tm.assert_numpy_array_equal(idx.isin([('bar', float('nan'))]),
2591+
np.array([False, True]))
2592+
25842593
def test_isin_level_kwarg(self):
25852594
idx = MultiIndex.from_arrays([['qux', 'baz', 'foo', 'bar'], np.arange(
25862595
4)])

0 commit comments

Comments
 (0)