Skip to content

Commit 0cff92d

Browse files
committed
DEPR: move NumericIndex._engine_type and NumericIndex.inferred_type to Index
1 parent 1c17d94 commit 0cff92d

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
@@ -2521,12 +2536,34 @@ def holds_integer(self) -> bool:
25212536
)
25222537
return self._holds_integer()
25232538

2539+
def _inferred_type(self) -> str_t:
2540+
"""
2541+
Return a string of the type inferred from the values.
2542+
"""
2543+
try: # fastpath numeric indexes
2544+
return {
2545+
"i": "integer",
2546+
"u": "integer",
2547+
"f": "floating",
2548+
"c": "complex",
2549+
}[self.dtype.kind]
2550+
except KeyError:
2551+
return lib.infer_dtype(self._values, skipna=False)
2552+
25242553
@cache_readonly
25252554
def inferred_type(self) -> str_t:
25262555
"""
25272556
Return a string of the type inferred from the values.
25282557
"""
2529-
return lib.infer_dtype(self._values, skipna=False)
2558+
try:
2559+
return {
2560+
"i": "integer",
2561+
"u": "integer",
2562+
"f": "floating",
2563+
"c": "complex",
2564+
}[self.dtype.kind]
2565+
except KeyError:
2566+
return lib.infer_dtype(self._values, skipna=False)
25302567

25312568
@cache_readonly
25322569
@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 (
98
Dtype,
109
npt,
@@ -77,36 +76,6 @@ class NumericIndex(Index):
7776
)
7877
_can_hold_strings = False
7978

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

0 commit comments

Comments
 (0)