Skip to content

Commit 5ec6139

Browse files
authored
TYP: make _engine_type consistently a property (#47664)
1 parent 63caef9 commit 5ec6139

9 files changed

+33
-15
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ repos:
9393
types: [python]
9494
stages: [manual]
9595
additional_dependencies: &pyright_dependencies
96-
96+
9797
- repo: local
9898
hooks:
9999
- id: pyright_reportGeneralTypeIssues

pandas/core/indexes/base.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,12 @@ def _outer_indexer(
404404
# associated code in pandas 2.0.
405405
_is_backward_compat_public_numeric_index: bool = False
406406

407-
_engine_type: type[libindex.IndexEngine] | type[
408-
libindex.ExtensionEngine
409-
] = libindex.ObjectEngine
407+
@property
408+
def _engine_type(
409+
self,
410+
) -> type[libindex.IndexEngine] | type[libindex.ExtensionEngine]:
411+
return libindex.ObjectEngine
412+
410413
# whether we support partial string indexing. Overridden
411414
# in DatetimeIndex and PeriodIndex
412415
_supports_partial_string_indexing = False

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def _should_fallback_to_positional(self) -> bool:
192192
_values: Categorical
193193

194194
@property
195-
def _engine_type(self):
195+
def _engine_type(self) -> type[libindex.IndexEngine]:
196196
# self.codes can have dtype int8, int16, int32 or int64, so we need
197197
# to return the corresponding engine type (libindex.Int8Engine, etc.).
198198
return {

pandas/core/indexes/datetimes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
252252
_typ = "datetimeindex"
253253

254254
_data_cls = DatetimeArray
255-
_engine_type = libindex.DatetimeEngine
256255
_supports_partial_string_indexing = True
257256

257+
@property
258+
def _engine_type(self) -> type[libindex.DatetimeEngine]:
259+
return libindex.DatetimeEngine
260+
258261
_data: DatetimeArray
259262
inferred_freq: str | None
260263
tz: tzinfo | None

pandas/core/indexes/numeric.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class NumericIndex(Index):
106106
}
107107

108108
@property
109-
def _engine_type(self):
109+
def _engine_type(self) -> type[libindex.IndexEngine]:
110110
# error: Invalid index type "Union[dtype[Any], ExtensionDtype]" for
111111
# "Dict[dtype[Any], Type[IndexEngine]]"; expected type "dtype[Any]"
112112
return self._engine_types[self.dtype] # type: ignore[index]
@@ -373,10 +373,13 @@ class Int64Index(IntegerIndex):
373373
__doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args
374374

375375
_typ = "int64index"
376-
_engine_type = libindex.Int64Engine
377376
_default_dtype = np.dtype(np.int64)
378377
_dtype_validation_metadata = (is_signed_integer_dtype, "signed integer")
379378

379+
@property
380+
def _engine_type(self) -> type[libindex.Int64Engine]:
381+
return libindex.Int64Engine
382+
380383

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

390393
_typ = "uint64index"
391-
_engine_type = libindex.UInt64Engine
392394
_default_dtype = np.dtype(np.uint64)
393395
_dtype_validation_metadata = (is_unsigned_integer_dtype, "unsigned integer")
394396

397+
@property
398+
def _engine_type(self) -> type[libindex.UInt64Engine]:
399+
return libindex.UInt64Engine
400+
395401

396402
class Float64Index(NumericIndex):
397403
_index_descr_args = {

pandas/core/indexes/period.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,12 @@ class PeriodIndex(DatetimeIndexOpsMixin):
159159
dtype: PeriodDtype
160160

161161
_data_cls = PeriodArray
162-
_engine_type = libindex.PeriodEngine
163162
_supports_partial_string_indexing = True
164163

164+
@property
165+
def _engine_type(self) -> type[libindex.PeriodEngine]:
166+
return libindex.PeriodEngine
167+
165168
@cache_readonly
166169
# Signature of "_resolution_obj" incompatible with supertype "DatetimeIndexOpsMixin"
167170
def _resolution_obj(self) -> Resolution: # type: ignore[override]

pandas/core/indexes/range.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ class RangeIndex(NumericIndex):
104104
"""
105105

106106
_typ = "rangeindex"
107-
_engine_type = libindex.Int64Engine
108107
_dtype_validation_metadata = (is_signed_integer_dtype, "signed integer")
109108
_range: range
110109
_is_backward_compat_public_numeric_index: bool = False
111110

111+
@property
112+
def _engine_type(self) -> type[libindex.Int64Engine]:
113+
return libindex.Int64Engine
114+
112115
# --------------------------------------------------------------------
113116
# Constructors
114117

pandas/core/indexes/timedeltas.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ class TimedeltaIndex(DatetimeTimedeltaMixin):
101101
_typ = "timedeltaindex"
102102

103103
_data_cls = TimedeltaArray
104-
_engine_type = libindex.TimedeltaEngine
104+
105+
@property
106+
def _engine_type(self) -> type[libindex.TimedeltaEngine]:
107+
return libindex.TimedeltaEngine
105108

106109
_data: TimedeltaArray
107110

pyright_reportGeneralTypeIssues.json

-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"pandas/io/clipboard",
1616
"pandas/util/version",
1717
# and all files that currently don't pass
18-
"pandas/_config/config.py",
1918
"pandas/_testing/__init__.py",
2019
"pandas/core/algorithms.py",
2120
"pandas/core/apply.py",
@@ -58,7 +57,6 @@
5857
"pandas/core/indexes/multi.py",
5958
"pandas/core/indexes/numeric.py",
6059
"pandas/core/indexes/period.py",
61-
"pandas/core/indexes/range.py",
6260
"pandas/core/indexing.py",
6361
"pandas/core/internals/api.py",
6462
"pandas/core/internals/array_manager.py",
@@ -80,7 +78,6 @@
8078
"pandas/core/tools/datetimes.py",
8179
"pandas/core/tools/timedeltas.py",
8280
"pandas/core/util/hashing.py",
83-
"pandas/core/util/numba_.py",
8481
"pandas/core/window/ewm.py",
8582
"pandas/core/window/rolling.py",
8683
"pandas/io/common.py",

0 commit comments

Comments
 (0)