Skip to content

Commit 69021e3

Browse files
authored
REF: de-duplicate intersection methods (#38283)
1 parent d6c6788 commit 69021e3

File tree

3 files changed

+0
-46
lines changed

3 files changed

+0
-46
lines changed

pandas/core/indexes/datetimelike.py

-4
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,6 @@ def _intersection(self, other: Index, sort=False) -> Index:
706706

707707
if not isinstance(other, type(self)):
708708
result = Index.intersection(self, other, sort=sort)
709-
if isinstance(result, type(self)):
710-
if result.freq is None:
711-
# TODO: no tests rely on this; needed?
712-
result = result._with_freq("infer")
713709
return result
714710

715711
elif not self._can_fast_intersect(other):

pandas/core/indexes/interval.py

-5
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ def wrapped(self, other, sort=False):
126126
self._assert_can_do_setop(other)
127127
other, _ = self._convert_can_do_setop(other)
128128

129-
if op_name == "intersection":
130-
if self.equals(other):
131-
return self._get_reconciled_name_object(other)
132-
133129
if not isinstance(other, IntervalIndex):
134130
result = getattr(self.astype(object), op_name)(other)
135131
if op_name in ("difference",):
@@ -965,7 +961,6 @@ def _assert_can_do_setop(self, other):
965961
)
966962

967963
@Appender(Index.intersection.__doc__)
968-
@setop_check
969964
def intersection(self, other, sort=False) -> Index:
970965
self._validate_sort_keyword(sort)
971966
self._assert_can_do_setop(other)

pandas/core/indexes/range.py

-37
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from pandas.core.dtypes.common import (
1616
ensure_platform_int,
1717
ensure_python_int,
18-
is_dtype_equal,
1918
is_float,
2019
is_integer,
2120
is_list_like,
@@ -483,42 +482,6 @@ def equals(self, other: object) -> bool:
483482
# --------------------------------------------------------------------
484483
# Set Operations
485484

486-
def intersection(self, other, sort=False):
487-
"""
488-
Form the intersection of two Index objects.
489-
490-
Parameters
491-
----------
492-
other : Index or array-like
493-
sort : False or None, default False
494-
Sort the resulting index if possible
495-
496-
.. versionadded:: 0.24.0
497-
498-
.. versionchanged:: 0.24.1
499-
500-
Changed the default to ``False`` to match the behaviour
501-
from before 0.24.0.
502-
503-
Returns
504-
-------
505-
intersection : Index
506-
"""
507-
self._validate_sort_keyword(sort)
508-
self._assert_can_do_setop(other)
509-
other, _ = self._convert_can_do_setop(other)
510-
511-
if self.equals(other) and not self.has_duplicates:
512-
# has_duplicates check is unnecessary for RangeIndex, but
513-
# used to match other subclasses.
514-
return self._get_reconciled_name_object(other)
515-
516-
if not is_dtype_equal(self.dtype, other.dtype):
517-
return super().intersection(other, sort=sort)
518-
519-
result = self._intersection(other, sort=sort)
520-
return self._wrap_setop_result(other, result)
521-
522485
def _intersection(self, other, sort=False):
523486

524487
if not isinstance(other, RangeIndex):

0 commit comments

Comments
 (0)