@@ -967,9 +967,20 @@ def intersection(self, other, sort=False) -> Index:
967
967
self ._assert_can_do_setop (other )
968
968
other , _ = self ._convert_can_do_setop (other )
969
969
970
+ if self .equals (other ) and not self .has_duplicates :
971
+ return self ._get_reconciled_name_object (other )
972
+
970
973
if not isinstance (other , IntervalIndex ):
971
974
return self .astype (object ).intersection (other )
972
975
976
+ result = self ._intersection (other , sort = sort )
977
+ return self ._wrap_setop_result (other , result )
978
+
979
+ def _intersection (self , other , sort ):
980
+ """
981
+ intersection specialized to the case with matching dtypes.
982
+ """
983
+ # For IntervalIndex we also know other.closed == self.closed
973
984
if self .left .is_unique and self .right .is_unique :
974
985
taken = self ._intersection_unique (other )
975
986
elif other .left .is_unique and other .right .is_unique and self .isna ().sum () <= 1 :
@@ -983,7 +994,7 @@ def intersection(self, other, sort=False) -> Index:
983
994
if sort is None :
984
995
taken = taken .sort_values ()
985
996
986
- return self . _wrap_setop_result ( other , taken )
997
+ return taken
987
998
988
999
def _intersection_unique (self , other : "IntervalIndex" ) -> "IntervalIndex" :
989
1000
"""
0 commit comments