@@ -122,6 +122,7 @@ def setop_check(method):
122
122
123
123
@wraps (method )
124
124
def wrapped (self , other , sort = False ):
125
+ self ._validate_sort_keyword (sort )
125
126
self ._assert_can_do_setop (other )
126
127
other = ensure_index (other )
127
128
@@ -131,14 +132,6 @@ def wrapped(self, other, sort=False):
131
132
result = result .astype (self .dtype )
132
133
return result
133
134
134
- if self ._is_non_comparable_own_type (other ):
135
- # GH#19016: ensure set op will not return a prohibited dtype
136
- raise TypeError (
137
- "can only do set operations between two IntervalIndex "
138
- "objects that are closed on the same side "
139
- "and have compatible dtypes"
140
- )
141
-
142
135
return method (self , other , sort )
143
136
144
137
return wrapped
@@ -956,11 +949,27 @@ def _format_space(self) -> str:
956
949
# --------------------------------------------------------------------
957
950
# Set Operations
958
951
952
+ def _assert_can_do_setop (self , other ):
953
+ super ()._assert_can_do_setop (other )
954
+
955
+ if isinstance (other , IntervalIndex ) and self ._is_non_comparable_own_type (other ):
956
+ # GH#19016: ensure set op will not return a prohibited dtype
957
+ raise TypeError (
958
+ "can only do set operations between two IntervalIndex "
959
+ "objects that are closed on the same side "
960
+ "and have compatible dtypes"
961
+ )
962
+
959
963
@Appender (Index .intersection .__doc__ )
960
964
@setop_check
961
- def intersection (
962
- self , other : "IntervalIndex" , sort : bool = False
963
- ) -> "IntervalIndex" :
965
+ def intersection (self , other , sort = False ) -> Index :
966
+ self ._validate_sort_keyword (sort )
967
+ self ._assert_can_do_setop (other )
968
+ other , _ = self ._convert_can_do_setop (other )
969
+
970
+ if not isinstance (other , IntervalIndex ):
971
+ return self .astype (object ).intersection (other )
972
+
964
973
if self .left .is_unique and self .right .is_unique :
965
974
taken = self ._intersection_unique (other )
966
975
elif other .left .is_unique and other .right .is_unique and self .isna ().sum () <= 1 :
0 commit comments