From dff7d4c321dab46b81dbf58873be57cd303c17fd Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 3 Dec 2020 19:40:13 -0800 Subject: [PATCH] REF: de-duplicate intersection methods --- pandas/core/indexes/datetimelike.py | 4 ---- pandas/core/indexes/interval.py | 5 ---- pandas/core/indexes/range.py | 37 ----------------------------- 3 files changed, 46 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 4912fe6949958..f0d4d36531e0d 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -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): diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 18be4bf225da5..f627b91958e75 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -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",): @@ -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) diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index a71376187a8c4..ec896d94a20ba 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -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, @@ -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):