Skip to content

Commit 2b0d1a1

Browse files
jbrockmendeljreback
authored andcommitted
share _wrap_joined_index (#30599)
1 parent f9fb02e commit 2b0d1a1

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
@@ -923,6 +924,22 @@ def _is_convertible_to_index_for_join(cls, other: Index) -> bool:
923924
return True
924925
return False
925926

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

927944
def wrap_arithmetic_op(self, other, result):
928945
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)