Skip to content

Commit

Permalink
REF: de-duplicate intersection methods (#38283)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Dec 4, 2020
1 parent d6c6788 commit 69021e3
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 46 deletions.
4 changes: 0 additions & 4 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,6 @@ def _intersection(self, other: Index, sort=False) -> Index:

if not isinstance(other, type(self)):
result = Index.intersection(self, other, sort=sort)
if isinstance(result, type(self)):
if result.freq is None:
# TODO: no tests rely on this; needed?
result = result._with_freq("infer")
return result

elif not self._can_fast_intersect(other):
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def wrapped(self, other, sort=False):
self._assert_can_do_setop(other)
other, _ = self._convert_can_do_setop(other)

if op_name == "intersection":
if self.equals(other):
return self._get_reconciled_name_object(other)

if not isinstance(other, IntervalIndex):
result = getattr(self.astype(object), op_name)(other)
if op_name in ("difference",):
Expand Down Expand Up @@ -965,7 +961,6 @@ def _assert_can_do_setop(self, other):
)

@Appender(Index.intersection.__doc__)
@setop_check
def intersection(self, other, sort=False) -> Index:
self._validate_sort_keyword(sort)
self._assert_can_do_setop(other)
Expand Down
37 changes: 0 additions & 37 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pandas.core.dtypes.common import (
ensure_platform_int,
ensure_python_int,
is_dtype_equal,
is_float,
is_integer,
is_list_like,
Expand Down Expand Up @@ -483,42 +482,6 @@ def equals(self, other: object) -> bool:
# --------------------------------------------------------------------
# Set Operations

def intersection(self, other, sort=False):
"""
Form the intersection of two Index objects.
Parameters
----------
other : Index or array-like
sort : False or None, default False
Sort the resulting index if possible
.. versionadded:: 0.24.0
.. versionchanged:: 0.24.1
Changed the default to ``False`` to match the behaviour
from before 0.24.0.
Returns
-------
intersection : Index
"""
self._validate_sort_keyword(sort)
self._assert_can_do_setop(other)
other, _ = self._convert_can_do_setop(other)

if self.equals(other) and not self.has_duplicates:
# has_duplicates check is unnecessary for RangeIndex, but
# used to match other subclasses.
return self._get_reconciled_name_object(other)

if not is_dtype_equal(self.dtype, other.dtype):
return super().intersection(other, sort=sort)

result = self._intersection(other, sort=sort)
return self._wrap_setop_result(other, result)

def _intersection(self, other, sort=False):

if not isinstance(other, RangeIndex):
Expand Down

0 comments on commit 69021e3

Please sign in to comment.