Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: de-duplicate intersection methods #38283

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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