@@ -130,19 +130,13 @@ def wrapped(self, other, sort=False):
130
130
if op_name in ("difference" ,):
131
131
result = result .astype (self .dtype )
132
132
return result
133
- elif self .closed != other .closed :
134
- raise ValueError (
135
- "can only do set operations between two IntervalIndex "
136
- "objects that are closed on the same side"
137
- )
138
133
139
- # GH 19016: ensure set op will not return a prohibited dtype
140
- subtypes = [self .dtype .subtype , other .dtype .subtype ]
141
- common_subtype = find_common_type (subtypes )
142
- if is_object_dtype (common_subtype ):
134
+ if self ._is_non_comparable_own_type (other ):
135
+ # GH#19016: ensure set op will not return a prohibited dtype
143
136
raise TypeError (
144
- f"can only do { op_name } between two IntervalIndex "
145
- "objects that have compatible dtypes"
137
+ "can only do set operations between two IntervalIndex "
138
+ "objects that are closed on the same side "
139
+ "and have compatible dtypes"
146
140
)
147
141
148
142
return method (self , other , sort )
@@ -717,11 +711,8 @@ def get_indexer(
717
711
if self .equals (target_as_index ):
718
712
return np .arange (len (self ), dtype = "intp" )
719
713
720
- # different closed or incompatible subtype -> no matches
721
- common_subtype = find_common_type (
722
- [self .dtype .subtype , target_as_index .dtype .subtype ]
723
- )
724
- if self .closed != target_as_index .closed or is_object_dtype (common_subtype ):
714
+ if self ._is_non_comparable_own_type (target_as_index ):
715
+ # different closed or incompatible subtype -> no matches
725
716
return np .repeat (np .intp (- 1 ), len (target_as_index ))
726
717
727
718
# non-overlapping -> at most one match per interval in target_as_index
@@ -763,10 +754,8 @@ def get_indexer_non_unique(
763
754
764
755
# check that target_as_index IntervalIndex is compatible
765
756
if isinstance (target_as_index , IntervalIndex ):
766
- common_subtype = find_common_type (
767
- [self .dtype .subtype , target_as_index .dtype .subtype ]
768
- )
769
- if self .closed != target_as_index .closed or is_object_dtype (common_subtype ):
757
+
758
+ if self ._is_non_comparable_own_type (target_as_index ):
770
759
# different closed or incompatible subtype -> no matches
771
760
return (
772
761
np .repeat (- 1 , len (target_as_index )),
@@ -837,6 +826,16 @@ def _convert_list_indexer(self, keyarr):
837
826
838
827
return locs
839
828
829
+ def _is_non_comparable_own_type (self , other : "IntervalIndex" ) -> bool :
830
+ # different closed or incompatible subtype -> no matches
831
+
832
+ # TODO: once closed is part of IntervalDtype, we can just define
833
+ # is_comparable_dtype GH#19371
834
+ if self .closed != other .closed :
835
+ return True
836
+ common_subtype = find_common_type ([self .dtype .subtype , other .dtype .subtype ])
837
+ return is_object_dtype (common_subtype )
838
+
840
839
# --------------------------------------------------------------------
841
840
842
841
@cache_readonly
0 commit comments