Skip to content

Commit 7310d90

Browse files
authored
REGR: Fix nan comparison for same Index object (#47326)
1 parent f7be58a commit 7310d90

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v1.4.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Fixed regressions
2020
- Fixed regression in :func:`read_fwf` raising ``ValueError`` when ``widths`` was specified with ``usecols`` (:issue:`46580`)
2121
- Fixed regression in :func:`concat` not sorting columns for mixed column names (:issue:`47127`)
2222
- Fixed regression in :meth:`.Groupby.transform` and :meth:`.Groupby.agg` failing with ``engine="numba"`` when the index was a :class:`MultiIndex` (:issue:`46867`)
23+
- Fixed regression in ``NaN`` comparison for :class:`Index` operations where the same object was compared (:issue:`47105`)
2324
- Fixed regression is :meth:`.Styler.to_latex` and :meth:`.Styler.to_html` where ``buf`` failed in combination with ``encoding`` (:issue:`47053`)
2425
- Fixed regression in :func:`read_csv` with ``index_col=False`` identifying first row as index names when ``header=None`` (:issue:`46955`)
2526
- Fixed regression in :meth:`.DataFrameGroupBy.agg` when used with list-likes or dict-likes and ``axis=1`` that would give incorrect results; now raises ``NotImplementedError`` (:issue:`46995`)

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6955,7 +6955,7 @@ def _cmp_method(self, other, op):
69556955
# TODO: should set MultiIndex._can_hold_na = False?
69566956
arr[self.isna()] = False
69576957
return arr
6958-
elif op in {operator.ne, operator.lt, operator.gt}:
6958+
elif op is operator.ne:
69596959
arr = np.zeros(len(self), dtype=bool)
69606960
if self._can_hold_na and not isinstance(self, ABCMultiIndex):
69616961
arr[self.isna()] = True

pandas/tests/indexes/test_base.py

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime
33
from io import StringIO
44
import math
5+
import operator
56
import re
67

78
import numpy as np
@@ -1604,3 +1605,16 @@ def test_get_attributes_dict_deprecated():
16041605
with tm.assert_produces_warning(DeprecationWarning):
16051606
attrs = idx._get_attributes_dict()
16061607
assert attrs == {"name": None}
1608+
1609+
1610+
@pytest.mark.parametrize("op", [operator.lt, operator.gt])
1611+
def test_nan_comparison_same_object(op):
1612+
# GH#47105
1613+
idx = Index([np.nan])
1614+
expected = np.array([False])
1615+
1616+
result = op(idx, idx)
1617+
tm.assert_numpy_array_equal(result, expected)
1618+
1619+
result = op(idx, idx.copy())
1620+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)