@@ -197,18 +197,14 @@ def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None:
197
197
"""
198
198
Ensure int64 dtype for Int64Index etc. but allow int32 etc. for NumericIndex.
199
199
200
- Assumed dtype has already been validated.
200
+ Assumes dtype has already been validated.
201
201
"""
202
202
if dtype is None :
203
203
return cls ._default_dtype
204
204
205
205
dtype = pandas_dtype (dtype )
206
206
assert isinstance (dtype , np .dtype )
207
-
208
- if cls ._default_dtype is None :
209
- return dtype
210
- else :
211
- return cls ._default_dtype
207
+ return dtype
212
208
213
209
def __contains__ (self , key ) -> bool :
214
210
"""
@@ -357,6 +353,16 @@ class IntegerIndex(NumericIndex):
357
353
358
354
_is_numeric_index : bool = False
359
355
356
+ @classmethod
357
+ @doc (NumericIndex ._ensure_dtype )
358
+ def _ensure_dtype (cls , dtype : Dtype | None ) -> np .dtype | None :
359
+ if dtype is None :
360
+ return cls ._default_dtype
361
+ dtype = pandas_dtype (dtype )
362
+ assert isinstance (dtype , np .dtype )
363
+
364
+ return cls ._default_dtype
365
+
360
366
@property
361
367
def asi8 (self ) -> np .ndarray :
362
368
# do not cache or you'll create a memory leak
@@ -422,3 +428,13 @@ class Float64Index(NumericIndex):
422
428
_default_dtype = np .dtype (np .float64 )
423
429
_dtype_validation_metadata = (is_float_dtype , "float" )
424
430
_is_numeric_index : bool = False
431
+
432
+ @classmethod
433
+ @doc (NumericIndex ._ensure_dtype )
434
+ def _ensure_dtype (cls , dtype : Dtype | None ) -> np .dtype | None :
435
+ if dtype is None :
436
+ return cls ._default_dtype
437
+ dtype = pandas_dtype (dtype )
438
+ assert isinstance (dtype , np .dtype )
439
+
440
+ return cls ._default_dtype
0 commit comments