Skip to content

Commit

Permalink
DEPR: move NumericIndex._engine_type and NumericIndex.inferred_type t…
Browse files Browse the repository at this point in the history
…o Index
  • Loading branch information
topper-123 committed Jan 23, 2023
1 parent 1c17d94 commit 0cff92d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
41 changes: 39 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,26 @@ def _outer_indexer(
_attributes: list[str] = ["name"]
_can_hold_strings: bool = True

_engine_types: dict[np.dtype | ExtensionDtype, type[libindex.IndexEngine]] = {
np.dtype(np.int8): libindex.Int8Engine,
np.dtype(np.int16): libindex.Int16Engine,
np.dtype(np.int32): libindex.Int32Engine,
np.dtype(np.int64): libindex.Int64Engine,
np.dtype(np.uint8): libindex.UInt8Engine,
np.dtype(np.uint16): libindex.UInt16Engine,
np.dtype(np.uint32): libindex.UInt32Engine,
np.dtype(np.uint64): libindex.UInt64Engine,
np.dtype(np.float32): libindex.Float32Engine,
np.dtype(np.float64): libindex.Float64Engine,
np.dtype(np.complex64): libindex.Complex64Engine,
np.dtype(np.complex128): libindex.Complex128Engine,
}

@property
def _engine_type(
self,
) -> type[libindex.IndexEngine] | type[libindex.ExtensionEngine]:
return libindex.ObjectEngine
return self._engine_types.get(self.dtype, libindex.ObjectEngine)

# whether we support partial string indexing. Overridden
# in DatetimeIndex and PeriodIndex
Expand Down Expand Up @@ -2521,12 +2536,34 @@ def holds_integer(self) -> bool:
)
return self._holds_integer()

def _inferred_type(self) -> str_t:
"""
Return a string of the type inferred from the values.
"""
try: # fastpath numeric indexes
return {
"i": "integer",
"u": "integer",
"f": "floating",
"c": "complex",
}[self.dtype.kind]
except KeyError:
return lib.infer_dtype(self._values, skipna=False)

@cache_readonly
def inferred_type(self) -> str_t:
"""
Return a string of the type inferred from the values.
"""
return lib.infer_dtype(self._values, skipna=False)
try:
return {
"i": "integer",
"u": "integer",
"f": "floating",
"c": "complex",
}[self.dtype.kind]
except KeyError:
return lib.infer_dtype(self._values, skipna=False)

@cache_readonly
@final
Expand Down
31 changes: 0 additions & 31 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np

from pandas._libs import index as libindex
from pandas._typing import (
Dtype,
npt,
Expand Down Expand Up @@ -77,36 +76,6 @@ class NumericIndex(Index):
)
_can_hold_strings = False

_engine_types: dict[np.dtype, type[libindex.IndexEngine]] = {
np.dtype(np.int8): libindex.Int8Engine,
np.dtype(np.int16): libindex.Int16Engine,
np.dtype(np.int32): libindex.Int32Engine,
np.dtype(np.int64): libindex.Int64Engine,
np.dtype(np.uint8): libindex.UInt8Engine,
np.dtype(np.uint16): libindex.UInt16Engine,
np.dtype(np.uint32): libindex.UInt32Engine,
np.dtype(np.uint64): libindex.UInt64Engine,
np.dtype(np.float32): libindex.Float32Engine,
np.dtype(np.float64): libindex.Float64Engine,
np.dtype(np.complex64): libindex.Complex64Engine,
np.dtype(np.complex128): libindex.Complex128Engine,
}

@property
def _engine_type(self) -> type[libindex.IndexEngine]:
# error: Invalid index type "Union[dtype[Any], ExtensionDtype]" for
# "Dict[dtype[Any], Type[IndexEngine]]"; expected type "dtype[Any]"
return self._engine_types[self.dtype] # type: ignore[index]

@cache_readonly
def inferred_type(self) -> str:
return {
"i": "integer",
"u": "integer",
"f": "floating",
"c": "complex",
}[self.dtype.kind]

def __new__(
cls, data=None, dtype: Dtype | None = None, copy: bool = False, name=None
) -> NumericIndex:
Expand Down

0 comments on commit 0cff92d

Please sign in to comment.