Skip to content

Commit 4b8385c

Browse files
committed
cleanups
1 parent d04da70 commit 4b8385c

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

pandas/_testing/asserters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ def assert_index_equal(
266266
left : Index
267267
right : Index
268268
exact : bool or {'equiv'}, default 'equiv'
269-
It True, check that the Index class, dtype and inferred_type are identical.
270-
If 'equiv', numeric indexes will only be compared by dtype and inferred_type.
271-
It False, do not check that Index class, dtype and inferred_type are identical.
269+
Whether to check the Index class, dtype and inferred_type
270+
are identical. If 'equiv', then RangeIndex can be substituted for
271+
Int64Index as well.
272272
check_names : bool, default True
273273
Whether to check the names attribute.
274274
check_less_precise : bool or int, default False

pandas/core/indexes/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def __new__(
441441

442442
# index-like
443443
elif isinstance(data, Index) and data._is_numeric_index and dtype is None:
444-
return type(data)(data, name=name, copy=copy)
444+
return data._constructor(data, name=name, copy=copy)
445445
elif isinstance(data, (np.ndarray, Index, ABCSeries)):
446446

447447
if isinstance(data, ABCMultiIndex):
@@ -5726,7 +5726,7 @@ def map(self, mapper, na_action=None):
57265726
attributes["dtype"] = self.dtype
57275727

57285728
if self._is_numeric_index and is_numeric_dtype(new_values.dtype):
5729-
return type(self)(new_values, **attributes)
5729+
return self._constructor(new_values, **attributes)
57305730

57315731
return Index(new_values, **attributes)
57325732

pandas/core/indexes/category.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def astype(self, dtype, copy: bool = True) -> Index:
289289

290290
categories = self.categories
291291
# the super method always returns Int64Index, UInt64Index and Float64Index
292-
# but if e.g. the categories are a NumIndex with dtype float32, we want to
292+
# but if the categories are a NumericIndex with dtype float32, we want to
293293
# return an index with the same dtype as self.categories.
294294
if categories._is_numeric_index:
295295
assert isinstance(categories, NumericIndex) # mypy complaint fix
@@ -301,7 +301,7 @@ def astype(self, dtype, copy: bool = True) -> Index:
301301
new_values = self._data.astype(dtype, copy=copy)
302302
# pass copy=False because any copying has been done in the
303303
# _data.astype call above
304-
return type(categories)(new_values, name=self.name, copy=False)
304+
return categories._constructor(new_values, name=self.name, copy=False)
305305

306306
return super().astype(dtype, copy=copy)
307307

pandas/core/indexes/numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def astype(self, dtype, copy=True):
242242
return NumericIndex(arr, name=self.name, dtype=dtype)
243243
elif self._is_numeric_index:
244244
if not is_extension_array_dtype(dtype) and is_numeric_dtype(dtype):
245-
return type(self)(self, dtype=dtype, copy=copy)
245+
return self._constructor(self, dtype=dtype, copy=copy)
246246

247247
return super().astype(dtype, copy=copy)
248248

pandas/tests/indexes/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def test_numpy_argsort(self, index):
357357
def test_repeat(self, simple_index):
358358
rep = 2
359359
idx = simple_index.copy()
360-
new_index_cls = type(idx) if not isinstance(idx, RangeIndex) else Int64Index
360+
new_index_cls = Int64Index if isinstance(idx, RangeIndex) else idx._constructor
361361
expected = new_index_cls(idx.values.repeat(rep), name=idx.name)
362362
tm.assert_index_equal(idx.repeat(rep), expected)
363363

0 commit comments

Comments
 (0)