@@ -635,27 +635,24 @@ def _setop(self, other, sort, opname: str):
635
635
def intersection (self , other , sort = False ):
636
636
self ._validate_sort_keyword (sort )
637
637
self ._assert_can_do_setop (other )
638
- other , _ = self ._convert_can_do_setop (other )
638
+ other , result_name = self ._convert_can_do_setop (other )
639
639
640
640
if self .equals (other ):
641
641
if self .has_duplicates :
642
642
return self .unique ()._get_reconciled_name_object (other )
643
643
return self ._get_reconciled_name_object (other )
644
644
645
- return self ._intersection (other , sort = sort )
646
-
647
- def _intersection ( self , other , sort = False ):
645
+ elif not self ._should_compare (other ):
646
+ # We can infer that the intersection is empty.
647
+ return Index ([], name = result_name )
648
648
649
- if is_object_dtype (other .dtype ):
650
- return self .astype ("O" ).intersection (other , sort = sort )
649
+ elif not is_dtype_equal (self .dtype , other .dtype ):
650
+ # i.e. object dtype
651
+ return super ().intersection (other , sort = sort )
651
652
652
- elif not self ._is_comparable_dtype (other .dtype ):
653
- # We can infer that the intersection is empty.
654
- # assert_can_do_setop ensures that this is not just a mismatched freq
655
- this = self [:0 ].astype ("O" )
656
- other = other [:0 ].astype ("O" )
657
- return this .intersection (other , sort = sort )
653
+ return self ._intersection (other , sort = sort )
658
654
655
+ def _intersection (self , other , sort = False ):
659
656
return self ._setop (other , sort , opname = "intersection" )
660
657
661
658
def difference (self , other , sort = None ):
0 commit comments