From d3b5ce620c93901ad9ed28738d4614911bde8dce Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 27 Nov 2020 08:15:23 -0800 Subject: [PATCH] REF: implement _should_compare --- pandas/core/indexes/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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?