@@ -228,8 +228,8 @@ def __contains__(self, key) -> bool:
228
228
229
229
@doc (Index .astype )
230
230
def astype (self , dtype , copy = True ):
231
+ dtype = pandas_dtype (dtype )
231
232
if is_float_dtype (self .dtype ):
232
- dtype = pandas_dtype (dtype )
233
233
if needs_i8_conversion (dtype ):
234
234
raise TypeError (
235
235
f"Cannot convert Float64Index to dtype { dtype } ; integer "
@@ -243,6 +243,9 @@ def astype(self, dtype, copy=True):
243
243
return Int64Index (arr , name = self .name )
244
244
else :
245
245
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 )
246
249
247
250
return super ().astype (dtype , copy = copy )
248
251
@@ -273,21 +276,6 @@ def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
273
276
# we will try to coerce to integers
274
277
return self ._maybe_cast_indexer (label )
275
278
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
-
291
279
# ----------------------------------------------------------------
292
280
293
281
@doc (Index ._shallow_copy )
0 commit comments