|
41 | 41 | no_default, |
42 | 42 | ) |
43 | 43 | from pandas._libs.missing import ( |
| 44 | + NA, |
44 | 45 | is_matching_na, |
45 | | - NA |
| 46 | + is_pdna, |
46 | 47 | ) |
47 | 48 | from pandas._libs.tslibs import ( |
48 | 49 | OutOfBoundsDatetime, |
@@ -7654,17 +7655,27 @@ def _cmp_method(self, other: object, op: Callable) -> Any: |
7654 | 7655 | Wrapper used to dispatch comparison operations. |
7655 | 7656 | """ |
7656 | 7657 | 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 | + |
7657 | 7668 | # fastpath |
7658 | 7669 | 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) |
7660 | 7671 | if self._can_hold_na and not isinstance(self, ABCMultiIndex): |
7661 | 7672 | # TODO: should set MultiIndex._can_hold_na = False? |
7662 | | - arr[self.isna()] = NA |
| 7673 | + arr[self.isna()] = False |
7663 | 7674 | return arr |
7664 | 7675 | elif op is operator.ne: |
7665 | | - arr = np.full(len(self), False, dtype=object) |
| 7676 | + arr = np.zeros(len(self), dtype=bool) |
7666 | 7677 | if self._can_hold_na and not isinstance(self, ABCMultiIndex): |
7667 | | - arr[self.isna()] = NA |
| 7678 | + arr[self.isna()] = True |
7668 | 7679 | return arr |
7669 | 7680 |
|
7670 | 7681 | if isinstance(other, (np.ndarray, Index, ABCSeries, ExtensionArray)) and len( |
|
0 commit comments