Skip to content

Commit 2ccf1f4

Browse files
committed
DEPR: move NumericIndex._engine_type and NumericIndex.inferred_type to Index
1 parent 79b2610 commit 2ccf1f4

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

pandas/core/indexes/base.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,26 @@ def _outer_indexer(
386386
_attributes: list[str] = ["name"]
387387
_can_hold_strings: bool = True
388388

389+
_engine_types: dict[np.dtype | ExtensionDtype, type[libindex.IndexEngine]] = {
390+
np.dtype(np.int8): libindex.Int8Engine,
391+
np.dtype(np.int16): libindex.Int16Engine,
392+
np.dtype(np.int32): libindex.Int32Engine,
393+
np.dtype(np.int64): libindex.Int64Engine,
394+
np.dtype(np.uint8): libindex.UInt8Engine,
395+
np.dtype(np.uint16): libindex.UInt16Engine,
396+
np.dtype(np.uint32): libindex.UInt32Engine,
397+
np.dtype(np.uint64): libindex.UInt64Engine,
398+
np.dtype(np.float32): libindex.Float32Engine,
399+
np.dtype(np.float64): libindex.Float64Engine,
400+
np.dtype(np.complex64): libindex.Complex64Engine,
401+
np.dtype(np.complex128): libindex.Complex128Engine,
402+
}
403+
389404
@property
390405
def _engine_type(
391406
self,
392407
) -> type[libindex.IndexEngine] | type[libindex.ExtensionEngine]:
393-
return libindex.ObjectEngine
408+
return self._engine_types.get(self.dtype, libindex.ObjectEngine)
394409

395410
# whether we support partial string indexing. Overridden
396411
# in DatetimeIndex and PeriodIndex
@@ -2540,12 +2555,34 @@ def holds_integer(self) -> bool:
25402555
)
25412556
return self._holds_integer()
25422557

2558+
def _inferred_type(self) -> str_t:
2559+
"""
2560+
Return a string of the type inferred from the values.
2561+
"""
2562+
try: # fastpath numeric indexes
2563+
return {
2564+
"i": "integer",
2565+
"u": "integer",
2566+
"f": "floating",
2567+
"c": "complex",
2568+
}[self.dtype.kind]
2569+
except KeyError:
2570+
return lib.infer_dtype(self._values, skipna=False)
2571+
25432572
@cache_readonly
25442573
def inferred_type(self) -> str_t:
25452574
"""
25462575
Return a string of the type inferred from the values.
25472576
"""
2548-
return lib.infer_dtype(self._values, skipna=False)
2577+
try:
2578+
return {
2579+
"i": "integer",
2580+
"u": "integer",
2581+
"f": "floating",
2582+
"c": "complex",
2583+
}[self.dtype.kind]
2584+
except KeyError:
2585+
return lib.infer_dtype(self._values, skipna=False)
25492586

25502587
@cache_readonly
25512588
@final

pandas/core/indexes/numeric.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import numpy as np
66

7-
from pandas._libs import index as libindex
87
from pandas._typing import Dtype
98
from pandas.util._decorators import (
109
cache_readonly,
@@ -74,36 +73,6 @@ class NumericIndex(Index):
7473
)
7574
_can_hold_strings = False
7675

77-
_engine_types: dict[np.dtype, type[libindex.IndexEngine]] = {
78-
np.dtype(np.int8): libindex.Int8Engine,
79-
np.dtype(np.int16): libindex.Int16Engine,
80-
np.dtype(np.int32): libindex.Int32Engine,
81-
np.dtype(np.int64): libindex.Int64Engine,
82-
np.dtype(np.uint8): libindex.UInt8Engine,
83-
np.dtype(np.uint16): libindex.UInt16Engine,
84-
np.dtype(np.uint32): libindex.UInt32Engine,
85-
np.dtype(np.uint64): libindex.UInt64Engine,
86-
np.dtype(np.float32): libindex.Float32Engine,
87-
np.dtype(np.float64): libindex.Float64Engine,
88-
np.dtype(np.complex64): libindex.Complex64Engine,
89-
np.dtype(np.complex128): libindex.Complex128Engine,
90-
}
91-
92-
@property
93-
def _engine_type(self) -> type[libindex.IndexEngine]:
94-
# error: Invalid index type "Union[dtype[Any], ExtensionDtype]" for
95-
# "Dict[dtype[Any], Type[IndexEngine]]"; expected type "dtype[Any]"
96-
return self._engine_types[self.dtype] # type: ignore[index]
97-
98-
@cache_readonly
99-
def inferred_type(self) -> str:
100-
return {
101-
"i": "integer",
102-
"u": "integer",
103-
"f": "floating",
104-
"c": "complex",
105-
}[self.dtype.kind]
106-
10776
def __new__(
10877
cls, data=None, dtype: Dtype | None = None, copy: bool = False, name=None
10978
) -> NumericIndex:

0 commit comments

Comments
 (0)