Skip to content

TYP: make _engine_type consistently a property #47664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ repos:
types: [python]
stages: [manual]
additional_dependencies: &pyright_dependencies
- [email protected].253
- [email protected].258
- repo: local
hooks:
- id: pyright_reportGeneralTypeIssues
Expand Down
9 changes: 6 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ def _outer_indexer(
# associated code in pandas 2.0.
_is_backward_compat_public_numeric_index: bool = False

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

# whether we support partial string indexing. Overridden
# in DatetimeIndex and PeriodIndex
_supports_partial_string_indexing = False
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _should_fallback_to_positional(self) -> bool:
_values: Categorical

@property
def _engine_type(self):
def _engine_type(self) -> type[libindex.IndexEngine]:
# self.codes can have dtype int8, int16, int32 or int64, so we need
# to return the corresponding engine type (libindex.Int8Engine, etc.).
return {
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
_typ = "datetimeindex"

_data_cls = DatetimeArray
_engine_type = libindex.DatetimeEngine
_supports_partial_string_indexing = True

@property
def _engine_type(self) -> type[libindex.DatetimeEngine]:
return libindex.DatetimeEngine

_data: DatetimeArray
inferred_freq: str | None
tz: tzinfo | None
Expand Down
12 changes: 9 additions & 3 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NumericIndex(Index):
}

@property
def _engine_type(self):
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]
Expand Down Expand Up @@ -373,10 +373,13 @@ class Int64Index(IntegerIndex):
__doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args

_typ = "int64index"
_engine_type = libindex.Int64Engine
_default_dtype = np.dtype(np.int64)
_dtype_validation_metadata = (is_signed_integer_dtype, "signed integer")

@property
def _engine_type(self) -> type[libindex.Int64Engine]:
return libindex.Int64Engine


class UInt64Index(IntegerIndex):
_index_descr_args = {
Expand All @@ -388,10 +391,13 @@ class UInt64Index(IntegerIndex):
__doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args

_typ = "uint64index"
_engine_type = libindex.UInt64Engine
_default_dtype = np.dtype(np.uint64)
_dtype_validation_metadata = (is_unsigned_integer_dtype, "unsigned integer")

@property
def _engine_type(self) -> type[libindex.UInt64Engine]:
return libindex.UInt64Engine


class Float64Index(NumericIndex):
_index_descr_args = {
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ class PeriodIndex(DatetimeIndexOpsMixin):
dtype: PeriodDtype

_data_cls = PeriodArray
_engine_type = libindex.PeriodEngine
_supports_partial_string_indexing = True

@property
def _engine_type(self) -> type[libindex.PeriodEngine]:
return libindex.PeriodEngine

@cache_readonly
# Signature of "_resolution_obj" incompatible with supertype "DatetimeIndexOpsMixin"
def _resolution_obj(self) -> Resolution: # type: ignore[override]
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ class RangeIndex(NumericIndex):
"""

_typ = "rangeindex"
_engine_type = libindex.Int64Engine
_dtype_validation_metadata = (is_signed_integer_dtype, "signed integer")
_range: range
_is_backward_compat_public_numeric_index: bool = False

@property
def _engine_type(self) -> type[libindex.Int64Engine]:
return libindex.Int64Engine

# --------------------------------------------------------------------
# Constructors

Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class TimedeltaIndex(DatetimeTimedeltaMixin):
_typ = "timedeltaindex"

_data_cls = TimedeltaArray
_engine_type = libindex.TimedeltaEngine

@property
def _engine_type(self) -> type[libindex.TimedeltaEngine]:
return libindex.TimedeltaEngine

_data: TimedeltaArray

Expand Down
3 changes: 0 additions & 3 deletions pyright_reportGeneralTypeIssues.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"pandas/io/clipboard",
"pandas/util/version",
# and all files that currently don't pass
"pandas/_config/config.py",
"pandas/_testing/__init__.py",
"pandas/core/algorithms.py",
"pandas/core/apply.py",
Expand Down Expand Up @@ -58,7 +57,6 @@
"pandas/core/indexes/multi.py",
"pandas/core/indexes/numeric.py",
"pandas/core/indexes/period.py",
"pandas/core/indexes/range.py",
"pandas/core/indexing.py",
"pandas/core/internals/api.py",
"pandas/core/internals/array_manager.py",
Expand All @@ -80,7 +78,6 @@
"pandas/core/tools/datetimes.py",
"pandas/core/tools/timedeltas.py",
"pandas/core/util/hashing.py",
"pandas/core/util/numba_.py",
"pandas/core/window/ewm.py",
"pandas/core/window/rolling.py",
"pandas/io/common.py",
Expand Down