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