Skip to content

Commit afdb801

Browse files
jbrockmendelhweecat
authored andcommitted
share _wrap_joined_index (pandas-dev#30599)
1 parent e749ea9 commit afdb801

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

pandas/core/indexes/datetimelike.py

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import pandas.core.indexes.base as ibase
3636
from pandas.core.indexes.base import Index, _index_shared_docs
3737
from pandas.core.indexes.numeric import Int64Index
38+
from pandas.core.ops import get_op_result_name
3839
from pandas.core.tools.timedeltas import to_timedelta
3940

4041
from pandas.tseries.frequencies import DateOffset, to_offset
@@ -924,6 +925,22 @@ def _is_convertible_to_index_for_join(cls, other: Index) -> bool:
924925
return True
925926
return False
926927

928+
def _wrap_joined_index(self, joined, other):
929+
name = get_op_result_name(self, other)
930+
if (
931+
isinstance(other, type(self))
932+
and self.freq == other.freq
933+
and self._can_fast_union(other)
934+
):
935+
joined = self._shallow_copy(joined)
936+
joined.name = name
937+
return joined
938+
else:
939+
kwargs = {}
940+
if hasattr(self, "tz"):
941+
kwargs["tz"] = getattr(other, "tz", None)
942+
return self._simple_new(joined, name, **kwargs)
943+
927944

928945
def wrap_arithmetic_op(self, other, result):
929946
if result is NotImplemented:

pandas/core/indexes/datetimes.py

-14
Original file line numberDiff line numberDiff line change
@@ -632,20 +632,6 @@ def snap(self, freq="S"):
632632
# we know it conforms; skip check
633633
return DatetimeIndex._simple_new(snapped, name=self.name, tz=self.tz, freq=freq)
634634

635-
def _wrap_joined_index(self, joined, other):
636-
name = get_op_result_name(self, other)
637-
if (
638-
isinstance(other, DatetimeIndex)
639-
and self.freq == other.freq
640-
and self._can_fast_union(other)
641-
):
642-
joined = self._shallow_copy(joined)
643-
joined.name = name
644-
return joined
645-
else:
646-
tz = getattr(other, "tz", None)
647-
return self._simple_new(joined, name, tz=tz)
648-
649635
def _parsed_string_to_bounds(self, reso, parsed):
650636
"""
651637
Calculate datetime bounds for parsed time string and its resolution.

pandas/core/indexes/timedeltas.py

-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
DatetimelikeDelegateMixin,
3232
DatetimeTimedeltaMixin,
3333
)
34-
from pandas.core.ops import get_op_result_name
3534

3635
from pandas.tseries.frequencies import to_offset
3736

@@ -283,18 +282,6 @@ def _union(self, other, sort):
283282
result._set_freq("infer")
284283
return result
285284

286-
def _wrap_joined_index(self, joined, other):
287-
name = get_op_result_name(self, other)
288-
if (
289-
isinstance(other, TimedeltaIndex)
290-
and self.freq == other.freq
291-
and self._can_fast_union(other)
292-
):
293-
joined = self._shallow_copy(joined, name=name)
294-
return joined
295-
else:
296-
return self._simple_new(joined, name)
297-
298285
def _fast_union(self, other):
299286
if len(other) == 0:
300287
return self.view(type(self))

0 commit comments

Comments
 (0)