Skip to content

Commit 59d90ba

Browse files
BUG: refactor support to Index edge case
1 parent 820d571 commit 59d90ba

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

pandas/core/indexes/base.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
no_default,
4242
)
4343
from pandas._libs.missing import (
44+
NA,
4445
is_matching_na,
45-
NA
46+
is_pdna,
4647
)
4748
from pandas._libs.tslibs import (
4849
OutOfBoundsDatetime,
@@ -7654,17 +7655,27 @@ def _cmp_method(self, other: object, op: Callable) -> Any:
76547655
Wrapper used to dispatch comparison operations.
76557656
"""
76567657
if isinstance(other, Index) and self.is_(other):
7658+
is_pdna_mask = is_pdna(np.asarray(self))
7659+
if is_pdna_mask.any():
7660+
if op in {operator.eq, operator.le, operator.ge}:
7661+
fill_value = True
7662+
elif op is operator.ne:
7663+
fill_value = False
7664+
arr = np.full(len(self), fill_value, dtype=object)
7665+
arr[is_pdna_mask] = NA
7666+
return arr
7667+
76577668
# fastpath
76587669
if op in {operator.eq, operator.le, operator.ge}:
7659-
arr = np.full(len(self), True, dtype=object)
7670+
arr = np.ones(len(self), dtype=bool)
76607671
if self._can_hold_na and not isinstance(self, ABCMultiIndex):
76617672
# TODO: should set MultiIndex._can_hold_na = False?
7662-
arr[self.isna()] = NA
7673+
arr[self.isna()] = False
76637674
return arr
76647675
elif op is operator.ne:
7665-
arr = np.full(len(self), False, dtype=object)
7676+
arr = np.zeros(len(self), dtype=bool)
76667677
if self._can_hold_na and not isinstance(self, ABCMultiIndex):
7667-
arr[self.isna()] = NA
7678+
arr[self.isna()] = True
76687679
return arr
76697680

76707681
if isinstance(other, (np.ndarray, Index, ABCSeries, ExtensionArray)) and len(

0 commit comments

Comments
 (0)