Skip to content

Commit 7003f2d

Browse files
committed
COMPAT: when "nan is nan" is not consistent across implementations
1 parent e01dd48 commit 7003f2d

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

@@ -1369,13 +1369,21 @@ def test_isin(self):
13691369
assert len(result) == 0
13701370
assert result.dtype == np.bool_
13711371

1372-
def test_isin_nan(self):
1372+
@pytest.mark.skipif(PYPY, reason="np.nan is float('nan') on PyPy")
1373+
def test_isin_nan_not_pypy(self):
1374+
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([float('nan')]),
1375+
np.array([False, False]))
1376+
1377+
@pytest.mark.skipif(not PYPY, reason="np.nan is float('nan') on PyPy")
1378+
def test_isin_nan_pypy(self):
1379+
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([float('nan')]),
1380+
np.array([False, True]))
1381+
1382+
def test_isin_nan_common(self):
13731383
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([np.nan]),
13741384
np.array([False, True]))
13751385
tm.assert_numpy_array_equal(Index(['a', pd.NaT]).isin([pd.NaT]),
13761386
np.array([False, True]))
1377-
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([float('nan')]),
1378-
np.array([False, False]))
13791387
tm.assert_numpy_array_equal(Index(['a', np.nan]).isin([pd.NaT]),
13801388
np.array([False, False]))
13811389

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
@@ -2573,13 +2573,22 @@ def test_isin(self):
25732573
assert len(result) == 0
25742574
assert result.dtype == np.bool_
25752575

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

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

0 commit comments

Comments
 (0)