Skip to content

Commit 15fd0e7

Browse files
authored
REF: de-duplicate _wrap_joined_index (#36282)
1 parent 2067d7e commit 15fd0e7

File tree

5 files changed

+7
-13
lines changed

5 files changed

+7
-13
lines changed

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3877,7 +3877,7 @@ def _join_monotonic(self, other, how="left", return_indexers=False):
38773877

38783878
def _wrap_joined_index(self, joined, other):
38793879
name = get_op_result_name(self, other)
3880-
return Index(joined, name=name)
3880+
return self._constructor(joined, name=name)
38813881

38823882
# --------------------------------------------------------------------
38833883
# Uncategorized Methods

pandas/core/indexes/category.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ def _wrap_joined_index(
767767
self, joined: np.ndarray, other: "CategoricalIndex"
768768
) -> "CategoricalIndex":
769769
name = get_op_result_name(self, other)
770-
return self._create_from_codes(joined, name=name)
770+
cat = self._data._from_backing_data(joined)
771+
return type(self)._simple_new(cat, name=name)
771772

772773

773774
CategoricalIndex._add_logical_methods_disabled()

pandas/core/indexes/datetimelike.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ def _wrap_joined_index(self, joined: np.ndarray, other):
603603
else:
604604
self = cast(DatetimeTimedeltaMixin, self)
605605
freq = self.freq if self._can_fast_union(other) else None
606-
new_data = type(self._data)._simple_new(joined, dtype=self.dtype, freq=freq)
606+
607+
new_data = self._data._from_backing_data(joined)
608+
new_data._freq = freq
607609

608610
return type(self)._simple_new(new_data, name=name)
609611

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3637,7 +3637,7 @@ def delete(self, loc):
36373637

36383638
def _wrap_joined_index(self, joined, other):
36393639
names = self.names if self.names == other.names else None
3640-
return MultiIndex.from_tuples(joined, names=names)
3640+
return self._constructor(joined, names=names)
36413641

36423642
@doc(Index.isin)
36433643
def isin(self, values, level=None):

pandas/core/indexes/numeric.py

-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from pandas.core import algorithms
3434
import pandas.core.common as com
3535
from pandas.core.indexes.base import Index, maybe_extract_name
36-
from pandas.core.ops import get_op_result_name
3736

3837
_num_index_shared_docs = dict()
3938

@@ -262,10 +261,6 @@ class Int64Index(IntegerIndex):
262261
_engine_type = libindex.Int64Engine
263262
_default_dtype = np.dtype(np.int64)
264263

265-
def _wrap_joined_index(self, joined, other):
266-
name = get_op_result_name(self, other)
267-
return Int64Index(joined, name=name)
268-
269264
@classmethod
270265
def _assert_safe_casting(cls, data, subarr):
271266
"""
@@ -324,10 +319,6 @@ def _convert_index_indexer(self, keyarr):
324319

325320
# ----------------------------------------------------------------
326321

327-
def _wrap_joined_index(self, joined, other):
328-
name = get_op_result_name(self, other)
329-
return UInt64Index(joined, name=name)
330-
331322
@classmethod
332323
def _assert_safe_casting(cls, data, subarr):
333324
"""

0 commit comments

Comments
 (0)