@@ -391,7 +391,6 @@ def _outer_indexer(
391
391
_comparables : list [str ] = ["name" ]
392
392
_attributes : list [str ] = ["name" ]
393
393
_is_numeric_dtype : bool = False
394
- _can_hold_na : bool = True
395
394
_can_hold_strings : bool = True
396
395
397
396
# Whether this index is a NumericIndex, but not a Int64Index, Float64Index,
@@ -2206,6 +2205,20 @@ def _get_grouper_for_level(self, mapper, *, level=None):
2206
2205
# --------------------------------------------------------------------
2207
2206
# Introspection Methods
2208
2207
2208
+ @cache_readonly
2209
+ @final
2210
+ def _can_hold_na (self ) -> bool :
2211
+ if isinstance (self .dtype , ExtensionDtype ):
2212
+ if isinstance (self .dtype , IntervalDtype ):
2213
+ # FIXME(GH#45720): this is inaccurate for integer-backed
2214
+ # IntervalArray, but without it other.categories.take raises
2215
+ # in IntervalArray._cmp_method
2216
+ return True
2217
+ return self .dtype ._can_hold_na
2218
+ if self .dtype .kind in ["i" , "u" , "b" ]:
2219
+ return False
2220
+ return True
2221
+
2209
2222
@final
2210
2223
@property
2211
2224
def is_monotonic (self ) -> bool :
@@ -2662,10 +2675,21 @@ def inferred_type(self) -> str_t:
2662
2675
return lib .infer_dtype (self ._values , skipna = False )
2663
2676
2664
2677
@cache_readonly
2678
+ @final
2665
2679
def _is_all_dates (self ) -> bool :
2666
2680
"""
2667
2681
Whether or not the index values only consist of dates.
2668
2682
"""
2683
+
2684
+ if needs_i8_conversion (self .dtype ):
2685
+ return True
2686
+ elif self .dtype != _dtype_obj :
2687
+ # TODO(ExtensionIndex): 3rd party EA might override?
2688
+ # Note: this includes IntervalIndex, even when the left/right
2689
+ # contain datetime-like objects.
2690
+ return False
2691
+ elif self ._is_multi :
2692
+ return False
2669
2693
return is_datetime_array (ensure_object (self ._values ))
2670
2694
2671
2695
@cache_readonly
@@ -6159,6 +6183,10 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
6159
6183
"""
6160
6184
Can we compare values of the given dtype to our own?
6161
6185
"""
6186
+ if self .dtype .kind == "b" :
6187
+ return dtype .kind == "b"
6188
+ elif is_numeric_dtype (self .dtype ):
6189
+ return is_numeric_dtype (dtype )
6162
6190
return True
6163
6191
6164
6192
@final
0 commit comments