Skip to content

Commit 1b8b428

Browse files
authored
CLN: remove dtype kwarg from _simple_new (#32260)
1 parent a713063 commit 1b8b428

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

Diff for: pandas/core/indexes/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def asi8(self):
451451
return None
452452

453453
@classmethod
454-
def _simple_new(cls, values, name=None, dtype=None):
454+
def _simple_new(cls, values, name: Label = None):
455455
"""
456456
We require that we have a dtype compat for the values. If we are passed
457457
a non-dtype compat, then coerce using the constructor.
@@ -3310,7 +3310,7 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
33103310
values = range(0)
33113311
else:
33123312
values = self._data[:0] # appropriately-dtyped empty array
3313-
target = self._simple_new(values, dtype=self.dtype, **attrs)
3313+
target = self._simple_new(values, **attrs)
33143314
else:
33153315
target = ensure_index(target)
33163316

Diff for: pandas/core/indexes/category.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ def _create_from_codes(self, codes, dtype=None, name=None):
226226
return CategoricalIndex(cat, name=name)
227227

228228
@classmethod
229-
def _simple_new(cls, values: Categorical, name=None, dtype=None):
230-
# GH#32204 dtype is included for compat with Index._simple_new
229+
def _simple_new(cls, values: Categorical, name: Label = None):
231230
assert isinstance(values, Categorical), type(values)
232231
result = object.__new__(cls)
233232

@@ -433,7 +432,7 @@ def where(self, cond, other=None):
433432
other = self._na_value
434433
values = np.where(cond, self.values, other)
435434
cat = Categorical(values, dtype=self.dtype)
436-
return self._shallow_copy(cat)
435+
return type(self)._simple_new(cat, name=self.name)
437436

438437
def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
439438
"""

Diff for: pandas/core/indexes/interval.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pandas._libs import Timedelta, Timestamp, lib
1111
from pandas._libs.interval import Interval, IntervalMixin, IntervalTree
12-
from pandas._typing import AnyArrayLike
12+
from pandas._typing import AnyArrayLike, Label
1313
from pandas.util._decorators import Appender, Substitution, cache_readonly
1414
from pandas.util._exceptions import rewrite_exception
1515

@@ -191,7 +191,7 @@ def func(intvidx_self, other, sort=False):
191191
class IntervalIndex(IntervalMixin, ExtensionIndex):
192192
_typ = "intervalindex"
193193
_comparables = ["name"]
194-
_attributes = ["name", "closed"]
194+
_attributes = ["name"]
195195

196196
# we would like our indexing holder to defer to us
197197
_defer_to_indexing = True
@@ -227,17 +227,15 @@ def __new__(
227227
return cls._simple_new(array, name)
228228

229229
@classmethod
230-
def _simple_new(cls, array, name, closed=None):
230+
def _simple_new(cls, array: IntervalArray, name: Label = None):
231231
"""
232232
Construct from an IntervalArray
233233
234234
Parameters
235235
----------
236236
array : IntervalArray
237-
name : str
237+
name : Label, default None
238238
Attached as result.name
239-
closed : Any
240-
Ignored.
241239
"""
242240
assert isinstance(array, IntervalArray), type(array)
243241

Diff for: pandas/core/indexes/period.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def __new__(
217217
return cls._simple_new(data, name=name)
218218

219219
@classmethod
220-
def _simple_new(cls, values, name=None, freq=None, **kwargs):
220+
def _simple_new(cls, values: PeriodArray, name: Label = None):
221221
"""
222222
Create a new PeriodIndex.
223223
@@ -228,7 +228,6 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs):
228228
or coercion.
229229
"""
230230
assert isinstance(values, PeriodArray), type(values)
231-
assert freq is None or freq == values.freq, (freq, values.freq)
232231

233232
result = object.__new__(cls)
234233
result._data = values

Diff for: pandas/core/indexes/range.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __new__(
9595
# RangeIndex
9696
if isinstance(start, RangeIndex):
9797
start = start._range
98-
return cls._simple_new(start, dtype=dtype, name=name)
98+
return cls._simple_new(start, name=name)
9999

100100
# validate the arguments
101101
if com.all_none(start, stop, step):
@@ -113,7 +113,7 @@ def __new__(
113113
raise ValueError("Step must not be zero")
114114

115115
rng = range(start, stop, step)
116-
return cls._simple_new(rng, dtype=dtype, name=name)
116+
return cls._simple_new(rng, name=name)
117117

118118
@classmethod
119119
def from_range(cls, data: range, name=None, dtype=None) -> "RangeIndex":
@@ -131,10 +131,10 @@ def from_range(cls, data: range, name=None, dtype=None) -> "RangeIndex":
131131
)
132132

133133
cls._validate_dtype(dtype)
134-
return cls._simple_new(data, dtype=dtype, name=name)
134+
return cls._simple_new(data, name=name)
135135

136136
@classmethod
137-
def _simple_new(cls, values: range, name=None, dtype=None) -> "RangeIndex":
137+
def _simple_new(cls, values: range, name: Label = None) -> "RangeIndex":
138138
result = object.__new__(cls)
139139

140140
assert isinstance(values, range)

Diff for: pandas/tests/indexes/period/test_constructors.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ def test_constructor_simple_new(self):
322322
idx = period_range("2007-01", name="p", periods=2, freq="M")
323323

324324
with pytest.raises(AssertionError, match="<class .*PeriodIndex'>"):
325-
idx._simple_new(idx, name="p", freq=idx.freq)
325+
idx._simple_new(idx, name="p")
326326

327-
result = idx._simple_new(idx._data, name="p", freq=idx.freq)
327+
result = idx._simple_new(idx._data, name="p")
328328
tm.assert_index_equal(result, idx)
329329

330330
with pytest.raises(AssertionError):
@@ -339,19 +339,19 @@ def test_constructor_simple_new_empty(self):
339339
# GH13079
340340
idx = PeriodIndex([], freq="M", name="p")
341341
with pytest.raises(AssertionError, match="<class .*PeriodIndex'>"):
342-
idx._simple_new(idx, name="p", freq="M")
342+
idx._simple_new(idx, name="p")
343343

344-
result = idx._simple_new(idx._data, name="p", freq="M")
344+
result = idx._simple_new(idx._data, name="p")
345345
tm.assert_index_equal(result, idx)
346346

347347
@pytest.mark.parametrize("floats", [[1.1, 2.1], np.array([1.1, 2.1])])
348348
def test_constructor_floats(self, floats):
349349
with pytest.raises(AssertionError, match="<class "):
350-
PeriodIndex._simple_new(floats, freq="M")
350+
PeriodIndex._simple_new(floats)
351351

352352
msg = "PeriodIndex does not allow floating point in construction"
353353
with pytest.raises(TypeError, match=msg):
354-
PeriodIndex(floats, freq="M")
354+
PeriodIndex(floats)
355355

356356
def test_constructor_nat(self):
357357
msg = "start and end must not be NaT"

0 commit comments

Comments
 (0)