@@ -1285,40 +1285,37 @@ def equals(self, other):
1285
1285
self .right .equals (other .right ) and
1286
1286
self .closed == other .closed )
1287
1287
1288
- def _setop (op_name , check_subtypes = False ):
1288
+ def _setop (op_name ):
1289
1289
def func (self , other ):
1290
1290
msg = ('can only do set operations between two IntervalIndex '
1291
1291
'objects that are closed on the same side' )
1292
1292
other = self ._as_like_interval_index (other , msg )
1293
1293
1294
- if check_subtypes :
1295
- # GH 19016: ensure set op will not return a prohibited dtype
1296
- subtypes = [self .dtype .subtype , other .dtype .subtype ]
1297
- result_subtype = find_common_type (subtypes )
1298
- if is_object_dtype (result_subtype ):
1299
- msg = ('can only do {op} between two IntervalIndex '
1300
- 'objects that have compatible dtypes' )
1301
- raise TypeError (msg .format (op = op_name ))
1302
- else :
1303
- result_subtype = self .dtype .subtype
1294
+ # GH 19016: ensure set op will not return a prohibited dtype
1295
+ subtypes = [self .dtype .subtype , other .dtype .subtype ]
1296
+ common_subtype = find_common_type (subtypes )
1297
+ if is_object_dtype (common_subtype ):
1298
+ msg = ('can only do {op} between two IntervalIndex '
1299
+ 'objects that have compatible dtypes' )
1300
+ raise TypeError (msg .format (op = op_name ))
1304
1301
1305
1302
result = getattr (self ._multiindex , op_name )(other ._multiindex )
1306
1303
result_name = self .name if self .name == other .name else None
1307
1304
1308
1305
# GH 19101: ensure empty results have correct dtype
1309
1306
if result .empty :
1310
- result = result .values .astype (result_subtype )
1307
+ result = result .values .astype (self . dtype . subtype )
1311
1308
else :
1312
1309
result = result .values
1313
1310
1314
1311
return type (self ).from_tuples (result , closed = self .closed ,
1315
1312
name = result_name )
1316
1313
return func
1317
1314
1318
- union = _setop ('union' , check_subtypes = True )
1315
+ union = _setop ('union' )
1319
1316
intersection = _setop ('intersection' )
1320
1317
difference = _setop ('difference' )
1321
- symmetric_difference = _setop ('symmetric_difference' , check_subtypes = True )
1318
+ symmetric_difference = _setop ('symmetric_difference' )
1322
1319
1323
1320
# TODO: arithmetic operations
1324
1321
0 commit comments