@@ -205,7 +205,11 @@ def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None:
205
205
206
206
dtype = pandas_dtype (dtype )
207
207
assert isinstance (dtype , np .dtype )
208
- return dtype
208
+
209
+ if cls ._is_numeric_index : # NumericIndex
210
+ return dtype
211
+ else : # Int64Index, UInt64Index etc.
212
+ return cls ._default_dtype
209
213
210
214
def __contains__ (self , key ) -> bool :
211
215
"""
@@ -354,16 +358,6 @@ class IntegerIndex(NumericIndex):
354
358
355
359
_is_numeric_index : bool = False
356
360
357
- @classmethod
358
- @doc (NumericIndex ._ensure_dtype )
359
- def _ensure_dtype (cls , dtype : Dtype | None ) -> np .dtype | None :
360
- if dtype is None :
361
- return cls ._default_dtype
362
- dtype = pandas_dtype (dtype )
363
- assert isinstance (dtype , np .dtype )
364
-
365
- return cls ._default_dtype
366
-
367
361
@property
368
362
def asi8 (self ) -> np .ndarray :
369
363
# do not cache or you'll create a memory leak
@@ -429,13 +423,3 @@ class Float64Index(NumericIndex):
429
423
_default_dtype = np .dtype (np .float64 )
430
424
_dtype_validation_metadata = (is_float_dtype , "float" )
431
425
_is_numeric_index : bool = False
432
-
433
- @classmethod
434
- @doc (NumericIndex ._ensure_dtype )
435
- def _ensure_dtype (cls , dtype : Dtype | None ) -> np .dtype | None :
436
- if dtype is None :
437
- return cls ._default_dtype
438
- dtype = pandas_dtype (dtype )
439
- assert isinstance (dtype , np .dtype )
440
-
441
- return cls ._default_dtype
0 commit comments