Skip to content

Commit f6dccc1

Browse files
committed
clean-ups after rebasing
1 parent 9c7d57b commit f6dccc1

File tree

2 files changed

+4
-39
lines changed

2 files changed

+4
-39
lines changed

pandas/core/indexes/base.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,29 +2431,6 @@ def _is_multi(self) -> bool:
24312431
"""
24322432
return isinstance(self, ABCMultiIndex)
24332433

2434-
@final
2435-
@classmethod
2436-
def _is_numeric_index(cls) -> bool:
2437-
"""
2438-
Check if this is a NumericIndex, but *not* Int64Index, UInt64Index, FloatIndex.
2439-
2440-
Used to check if an operation should return NumericIndex or plain Index.
2441-
"""
2442-
from pandas import (
2443-
Float64Index,
2444-
Int64Index,
2445-
NumericIndex,
2446-
RangeIndex,
2447-
UInt64Index,
2448-
)
2449-
2450-
if not issubclass(cls, NumericIndex):
2451-
return False
2452-
elif issubclass(cls, (RangeIndex, Int64Index, UInt64Index, Float64Index)):
2453-
return False
2454-
else:
2455-
return True
2456-
24572434
# --------------------------------------------------------------------
24582435
# Pickle Methods
24592436

pandas/core/indexes/numeric.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ def __contains__(self, key) -> bool:
228228

229229
@doc(Index.astype)
230230
def astype(self, dtype, copy=True):
231+
dtype = pandas_dtype(dtype)
231232
if is_float_dtype(self.dtype):
232-
dtype = pandas_dtype(dtype)
233233
if needs_i8_conversion(dtype):
234234
raise TypeError(
235235
f"Cannot convert Float64Index to dtype {dtype}; integer "
@@ -243,6 +243,9 @@ def astype(self, dtype, copy=True):
243243
return Int64Index(arr, name=self.name)
244244
else:
245245
return NumericIndex(arr, name=self.name, dtype=dtype)
246+
elif self._is_numeric_index:
247+
if not is_extension_array_dtype(dtype) and is_numeric_dtype(dtype):
248+
return type(self)(self, dtype=dtype, copy=copy)
246249

247250
return super().astype(dtype, copy=copy)
248251

@@ -273,21 +276,6 @@ def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
273276
# we will try to coerce to integers
274277
return self._maybe_cast_indexer(label)
275278

276-
@doc(Index._convert_arr_indexer)
277-
def _convert_arr_indexer(self, keyarr) -> np.ndarray:
278-
if not is_unsigned_integer_dtype(self.dtype):
279-
return super()._convert_arr_indexer(keyarr)
280-
281-
# Cast the indexer to uint64 if possible so that the values returned
282-
# from indexing are also uint64.
283-
dtype = None
284-
if is_integer_dtype(keyarr) or (
285-
lib.infer_dtype(keyarr, skipna=False) == "integer"
286-
):
287-
dtype = np.dtype(np.uint64)
288-
289-
return com.asarray_tuplesafe(keyarr, dtype=dtype)
290-
291279
# ----------------------------------------------------------------
292280

293281
@doc(Index._shallow_copy)

0 commit comments

Comments
 (0)