Check if `self == other` can ever have non-False entries.
(self, other: Index)
| 6515 | |
| 6516 | @final |
| 6517 | def _should_compare(self, other: Index) -> bool: |
| 6518 | """ |
| 6519 | Check if `self == other` can ever have non-False entries. |
| 6520 | """ |
| 6521 | |
| 6522 | # NB: we use inferred_type rather than is_bool_dtype to catch |
| 6523 | # object_dtype_of_bool and categorical[object_dtype_of_bool] cases |
| 6524 | if ( |
| 6525 | other.inferred_type == "boolean" and is_any_real_numeric_dtype(self.dtype) |
| 6526 | ) or ( |
| 6527 | self.inferred_type == "boolean" and is_any_real_numeric_dtype(other.dtype) |
| 6528 | ): |
| 6529 | # GH#16877 Treat boolean labels passed to a numeric index as not |
| 6530 | # found. Without this fix False and True would be treated as 0 and 1 |
| 6531 | # respectively. |
| 6532 | return False |
| 6533 | |
| 6534 | dtype = _unpack_nested_dtype(other) |
| 6535 | return ( |
| 6536 | self._is_comparable_dtype(dtype) |
| 6537 | or is_object_dtype(dtype) |
| 6538 | or is_string_dtype(dtype) |
| 6539 | ) |
| 6540 | |
| 6541 | def _is_comparable_dtype(self, dtype: DtypeObj) -> bool: |
| 6542 | """ |
no test coverage detected