1
+ from __future__ import annotations
2
+
1
3
from typing import (
4
+ Callable ,
2
5
Hashable ,
3
- Optional ,
4
6
)
5
7
import warnings
6
8
@@ -49,11 +51,12 @@ class NumericIndex(Index):
49
51
"""
50
52
51
53
_default_dtype : np .dtype
54
+ _dtype_validation_metadata : tuple [Callable [..., bool ], str ]
52
55
53
56
_is_numeric_dtype = True
54
57
_can_hold_strings = False
55
58
56
- def __new__ (cls , data = None , dtype : Optional [ Dtype ] = None , copy = False , name = None ):
59
+ def __new__ (cls , data = None , dtype : Dtype | None = None , copy = False , name = None ):
57
60
name = maybe_extract_name (name , data , cls )
58
61
59
62
subarr = cls ._ensure_array (data , dtype , copy )
@@ -97,14 +100,8 @@ def _ensure_array(cls, data, dtype, copy: bool):
97
100
def _validate_dtype (cls , dtype : Dtype ) -> None :
98
101
if dtype is None :
99
102
return
100
- validation_metadata = {
101
- "int64index" : (is_signed_integer_dtype , "signed integer" ),
102
- "uint64index" : (is_unsigned_integer_dtype , "unsigned integer" ),
103
- "float64index" : (is_float_dtype , "float" ),
104
- "rangeindex" : (is_signed_integer_dtype , "signed integer" ),
105
- }
106
-
107
- validation_func , expected = validation_metadata [cls ._typ ]
103
+
104
+ validation_func , expected = cls ._dtype_validation_metadata
108
105
if not validation_func (dtype ):
109
106
raise ValueError (
110
107
f"Incorrect `dtype` passed: expected { expected } , received { dtype } "
@@ -264,6 +261,7 @@ class Int64Index(IntegerIndex):
264
261
_typ = "int64index"
265
262
_engine_type = libindex .Int64Engine
266
263
_default_dtype = np .dtype (np .int64 )
264
+ _dtype_validation_metadata = (is_signed_integer_dtype , "signed integer" )
267
265
268
266
269
267
_uint64_descr_args = {
@@ -280,6 +278,7 @@ class UInt64Index(IntegerIndex):
280
278
_typ = "uint64index"
281
279
_engine_type = libindex .UInt64Engine
282
280
_default_dtype = np .dtype (np .uint64 )
281
+ _dtype_validation_metadata = (is_unsigned_integer_dtype , "unsigned integer" )
283
282
284
283
# ----------------------------------------------------------------
285
284
# Indexing Methods
@@ -311,6 +310,7 @@ class Float64Index(NumericIndex):
311
310
_typ = "float64index"
312
311
_engine_type = libindex .Float64Engine
313
312
_default_dtype = np .dtype (np .float64 )
313
+ _dtype_validation_metadata = (is_float_dtype , "float" )
314
314
315
315
@property
316
316
def inferred_type (self ) -> str :
0 commit comments