@@ -3059,6 +3059,7 @@ def _union(self, other: Index, sort):
3059
3059
and self .is_monotonic
3060
3060
and other .is_monotonic
3061
3061
and not (self .has_duplicates and other .has_duplicates )
3062
+ and self ._can_use_libjoin
3062
3063
):
3063
3064
# Both are unique and monotonic, so can use outer join
3064
3065
try :
@@ -3189,13 +3190,7 @@ def _intersection(self, other: Index, sort=False):
3189
3190
"""
3190
3191
intersection specialized to the case with matching dtypes.
3191
3192
"""
3192
- if (
3193
- self .is_monotonic
3194
- and other .is_monotonic
3195
- and not is_interval_dtype (self .dtype )
3196
- ):
3197
- # For IntervalIndex _inner_indexer is not more performant than get_indexer,
3198
- # so don't take this fastpath
3193
+ if self .is_monotonic and other .is_monotonic and self ._can_use_libjoin :
3199
3194
try :
3200
3195
result = self ._inner_indexer (other )[0 ]
3201
3196
except TypeError :
@@ -4178,12 +4173,15 @@ def join(
4178
4173
return self ._join_non_unique (other , how = how )
4179
4174
elif not self .is_unique or not other .is_unique :
4180
4175
if self .is_monotonic and other .is_monotonic :
4181
- return self ._join_monotonic (other , how = how )
4176
+ if self ._can_use_libjoin :
4177
+ # otherwise we will fall through to _join_via_get_indexer
4178
+ return self ._join_monotonic (other , how = how )
4182
4179
else :
4183
4180
return self ._join_non_unique (other , how = how )
4184
4181
elif (
4185
4182
self .is_monotonic
4186
4183
and other .is_monotonic
4184
+ and self ._can_use_libjoin
4187
4185
and (
4188
4186
not isinstance (self , ABCMultiIndex )
4189
4187
or not any (is_categorical_dtype (dtype ) for dtype in self .dtypes )
@@ -4545,6 +4543,15 @@ def _wrap_joined_index(self: _IndexT, joined: ArrayLike, other: _IndexT) -> _Ind
4545
4543
name = get_op_result_name (self , other )
4546
4544
return self ._constructor ._with_infer (joined , name = name )
4547
4545
4546
+ @cache_readonly
4547
+ def _can_use_libjoin (self ) -> bool :
4548
+ """
4549
+ Whether we can use the fastpaths implement in _libs.join
4550
+ """
4551
+ # Note: this will need to be updated when e.g. Nullable dtypes
4552
+ # are supported in Indexes.
4553
+ return not is_interval_dtype (self .dtype )
4554
+
4548
4555
# --------------------------------------------------------------------
4549
4556
# Uncategorized Methods
4550
4557
0 commit comments