Skip to content

REF: share _wrap_joined_index #30599

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

Merged
merged 1 commit into from
Jan 1, 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
17 changes: 17 additions & 0 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import pandas.core.indexes.base as ibase
from pandas.core.indexes.base import Index, _index_shared_docs
from pandas.core.indexes.numeric import Int64Index
from pandas.core.ops import get_op_result_name
from pandas.core.tools.timedeltas import to_timedelta

from pandas.tseries.frequencies import DateOffset, to_offset
Expand Down Expand Up @@ -923,6 +924,22 @@ def _is_convertible_to_index_for_join(cls, other: Index) -> bool:
return True
return False

def _wrap_joined_index(self, joined, other):
name = get_op_result_name(self, other)
if (
isinstance(other, type(self))
and self.freq == other.freq
and self._can_fast_union(other)
):
joined = self._shallow_copy(joined)
joined.name = name
return joined
else:
kwargs = {}
if hasattr(self, "tz"):
kwargs["tz"] = getattr(other, "tz", None)
return self._simple_new(joined, name, **kwargs)


def wrap_arithmetic_op(self, other, result):
if result is NotImplemented:
Expand Down
14 changes: 0 additions & 14 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,20 +632,6 @@ def snap(self, freq="S"):
# we know it conforms; skip check
return DatetimeIndex._simple_new(snapped, name=self.name, tz=self.tz, freq=freq)

def _wrap_joined_index(self, joined, other):
name = get_op_result_name(self, other)
if (
isinstance(other, DatetimeIndex)
and self.freq == other.freq
and self._can_fast_union(other)
):
joined = self._shallow_copy(joined)
joined.name = name
return joined
else:
tz = getattr(other, "tz", None)
return self._simple_new(joined, name, tz=tz)

def _parsed_string_to_bounds(self, reso, parsed):
"""
Calculate datetime bounds for parsed time string and its resolution.
Expand Down
13 changes: 0 additions & 13 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
DatetimelikeDelegateMixin,
DatetimeTimedeltaMixin,
)
from pandas.core.ops import get_op_result_name

from pandas.tseries.frequencies import to_offset

Expand Down Expand Up @@ -283,18 +282,6 @@ def _union(self, other, sort):
result._set_freq("infer")
return result

def _wrap_joined_index(self, joined, other):
name = get_op_result_name(self, other)
if (
isinstance(other, TimedeltaIndex)
and self.freq == other.freq
and self._can_fast_union(other)
):
joined = self._shallow_copy(joined, name=name)
return joined
else:
return self._simple_new(joined, name)

def _fast_union(self, other):
if len(other) == 0:
return self.view(type(self))
Expand Down