Skip to content

Commit 9bef78d

Browse files
jbrockmendeljreback
authored andcommitted
CLN: tighten what we pass to Index._shallow_copy (#31371)
1 parent 4d875eb commit 9bef78d

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

pandas/core/indexes/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,6 @@ def _shallow_copy(self, values=None, **kwargs):
507507

508508
attributes = self._get_attributes_dict()
509509
attributes.update(kwargs)
510-
if not len(values) and "dtype" not in kwargs:
511-
attributes["dtype"] = self.dtype
512-
513-
# _simple_new expects the type of self._data
514-
values = getattr(values, "_values", values)
515510

516511
return self._simple_new(values, **attributes)
517512

@@ -2354,6 +2349,9 @@ def _get_unique_index(self, dropna: bool = False):
23542349

23552350
if not self.is_unique:
23562351
values = self.unique()
2352+
if not isinstance(self, ABCMultiIndex):
2353+
# extract an array to pass to _shallow_copy
2354+
values = values._data
23572355

23582356
if dropna:
23592357
try:

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def union_many(self, others):
377377

378378
def _wrap_setop_result(self, other, result):
379379
name = get_op_result_name(self, other)
380-
return self._shallow_copy(result, name=name, freq=None, tz=self.tz)
380+
return self._shallow_copy(result, name=name, freq=None)
381381

382382
# --------------------------------------------------------------------
383383

0 commit comments

Comments
 (0)