From e60d151db80786797fdbc40d342088318cae1083 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 31 May 2021 16:49:50 -0700 Subject: [PATCH 1/2] CLN: datetimelike setops --- pandas/core/indexes/datetimelike.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 5f24eb0cfaad6..1428994081e84 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -632,10 +632,6 @@ def is_type_compatible(self, kind: str) -> bool: # -------------------------------------------------------------------- # Set Operation Methods - def _difference(self, other, sort=None): - new_idx = super()._difference(other, sort=sort)._with_freq(None) - return new_idx - def _intersection(self, other: Index, sort=False) -> Index: """ intersection specialized to the case with matching dtypes. @@ -774,20 +770,15 @@ def _fast_union(self: _T, other: _T, sort=None) -> _T: else: return left - def _union(self, other, sort): + def _union(self: _T, other: _T, sort) -> _T: # We are called by `union`, which is responsible for this validation assert isinstance(other, type(self)) assert self.dtype == other.dtype if self._can_fast_union(other): result = self._fast_union(other, sort=sort) - if sort is None: - # In the case where sort is None, _can_fast_union - # implies that result.freq should match self.freq - assert result.freq == self.freq, (result.freq, self.freq) - elif result.freq is None: - # TODO: no tests rely on this; needed? - result = result._with_freq("infer") + # in the case with sort=None, the _can_fast_union check ensures + # that result.freq == self.freq return result else: i8self = Int64Index._simple_new(self.asi8) From 01d049653da442b0d5d726ae11919bb1cb985ae0 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 31 May 2021 17:41:10 -0700 Subject: [PATCH 2/2] mypy fixup --- pandas/core/indexes/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 1428994081e84..484b581a898d8 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -770,7 +770,7 @@ def _fast_union(self: _T, other: _T, sort=None) -> _T: else: return left - def _union(self: _T, other: _T, sort) -> _T: + def _union(self, other, sort): # We are called by `union`, which is responsible for this validation assert isinstance(other, type(self)) assert self.dtype == other.dtype