diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c49f3f9457161..d3abeeebb5195 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4973,6 +4973,22 @@ def _maybe_promote(self, other: "Index"): return self, other + def _get_other_deep(self, other: "Index") -> "Index": + dtype = other.dtype + if is_categorical_dtype(dtype): + # If there is ever a SparseIndex, this could get dispatched + # here too. + return dtype.categories + return other + + def _should_compare(self, other: "Index") -> bool: + """ + Check if `self == other` can ever have non-False entries. + """ + other = self._get_other_deep(other) + dtype = other.dtype + return self._is_comparable_dtype(dtype) or is_object_dtype(dtype) + def _is_comparable_dtype(self, dtype: DtypeObj) -> bool: """ Can we compare values of the given dtype to our own?