MCPcopy
hub / github.com/pandas-dev/pandas / _should_compare

Method _should_compare

pandas/core/indexes/base.py:6517–6539  ·  view source on GitHub ↗

Check if `self == other` can ever have non-False entries.

(self, other: Index)

Source from the content-addressed store, hash-verified

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 """

Callers 8

intersectionMethod · 0.95
differenceMethod · 0.95
symmetric_differenceMethod · 0.95
get_indexerMethod · 0.95
equalsMethod · 0.80
_should_partial_indexMethod · 0.80

Calls 5

_is_comparable_dtypeMethod · 0.95
is_object_dtypeFunction · 0.90
is_string_dtypeFunction · 0.90
_unpack_nested_dtypeFunction · 0.85

Tested by

no test coverage detected