Skip to content

Commit a66e149

Browse files
authored
PERF: IntegerIndex._shallow_copy (#32130)
1 parent 628dfba commit a66e149

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pandas/core/indexes/numeric.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,16 @@ def _maybe_cast_slice_bound(self, label, side, kind):
103103
return self._maybe_cast_indexer(label)
104104

105105
@Appender(Index._shallow_copy.__doc__)
106-
def _shallow_copy(self, values=None, **kwargs):
107-
if values is not None and not self._can_hold_na:
106+
def _shallow_copy(self, values=None, name=lib.no_default):
107+
name = name if name is not lib.no_default else self.name
108+
109+
if values is not None and not self._can_hold_na and values.dtype.kind == "f":
108110
# Ensure we are not returning an Int64Index with float data:
109-
return self._shallow_copy_with_infer(values=values, **kwargs)
110-
return super()._shallow_copy(values=values, **kwargs)
111+
return Float64Index._simple_new(values, name=name)
112+
113+
if values is None:
114+
values = self.values
115+
return type(self)._simple_new(values, name=name)
111116

112117
def _convert_for_op(self, value):
113118
"""

0 commit comments

Comments
 (0)