@@ -3060,7 +3060,7 @@ def _union(self, other: Index, sort):
3060
3060
try :
3061
3061
return self ._outer_indexer (other )[0 ]
3062
3062
except (TypeError , IncompatibleFrequency ):
3063
- # incomparable objects
3063
+ # incomparable objects; should only be for object dtype
3064
3064
value_list = list (lvals )
3065
3065
3066
3066
# worth making this faster? a very unusual case
@@ -3074,7 +3074,7 @@ def _union(self, other: Index, sort):
3074
3074
result = algos .union_with_duplicates (lvals , rvals )
3075
3075
return _maybe_try_sort (result , sort )
3076
3076
3077
- # Self may have duplicates
3077
+ # Self may have duplicates; other already checked as unique
3078
3078
# find indexes of things in "other" that are not in "self"
3079
3079
if self ._index_as_unique :
3080
3080
indexer = self .get_indexer (other )
@@ -3089,6 +3089,7 @@ def _union(self, other: Index, sort):
3089
3089
result = lvals
3090
3090
3091
3091
if not self .is_monotonic or not other .is_monotonic :
3092
+ # if both are monotonic then result should already be sorted
3092
3093
result = _maybe_try_sort (result , sort )
3093
3094
3094
3095
return result
@@ -3194,6 +3195,7 @@ def _intersection(self, other: Index, sort=False):
3194
3195
try :
3195
3196
result = self ._inner_indexer (other )[0 ]
3196
3197
except TypeError :
3198
+ # non-comparable; should only be for object dtype
3197
3199
pass
3198
3200
else :
3199
3201
# TODO: algos.unique1d should preserve DTA/TDA
@@ -4485,7 +4487,7 @@ def _get_leaf_sorter(labels: list[np.ndarray]) -> npt.NDArray[np.intp]:
4485
4487
def _join_monotonic (
4486
4488
self , other : Index , how : str_t = "left"
4487
4489
) -> tuple [Index , npt .NDArray [np .intp ] | None , npt .NDArray [np .intp ] | None ]:
4488
- # We only get here with matching dtypes
4490
+ # We only get here with matching dtypes and both monotonic increasing
4489
4491
assert other .dtype == self .dtype
4490
4492
4491
4493
if self .equals (other ):
0 commit comments