Skip to content

Commit a01c099

Browse files
committed
upgrade mypy to 1.17.1 and pyright to 1.1.404 and make changes to support that
1 parent ce80252 commit a01c099

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+303
-272
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ repos:
121121
types: [python]
122122
stages: [manual]
123123
additional_dependencies: &pyright_dependencies
124-
124+
125125
- id: pyright
126126
# note: assumes python env is setup and activated
127127
name: pyright reportGeneralTypeIssues

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dependencies:
7777

7878
# code checks
7979
- flake8=7.1.0 # run in subprocess over docstring examples
80-
- mypy=1.13.0 # pre-commit uses locally installed mypy
80+
- mypy=1.17.1 # pre-commit uses locally installed mypy
8181
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
8282
- pre-commit>=4.2.0
8383

pandas/_libs/tslibs/dtypes.pyi

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,35 @@ class PeriodDtypeBase:
2828
def _td64_unit(self) -> str: ...
2929

3030
class FreqGroup(Enum):
31-
FR_ANN: int
32-
FR_QTR: int
33-
FR_MTH: int
34-
FR_WK: int
35-
FR_BUS: int
36-
FR_DAY: int
37-
FR_HR: int
38-
FR_MIN: int
39-
FR_SEC: int
40-
FR_MS: int
41-
FR_US: int
42-
FR_NS: int
43-
FR_UND: int
31+
_value_: int
32+
FR_ANN = ...
33+
FR_QTR = ...
34+
FR_MTH = ...
35+
FR_WK = ...
36+
FR_BUS = ...
37+
FR_DAY = ...
38+
FR_HR = ...
39+
FR_MIN = ...
40+
FR_SEC = ...
41+
FR_MS = ...
42+
FR_US = ...
43+
FR_NS = ...
44+
FR_UND = ...
4445
@staticmethod
4546
def from_period_dtype_code(code: int) -> FreqGroup: ...
4647

4748
class Resolution(Enum):
48-
RESO_NS: int
49-
RESO_US: int
50-
RESO_MS: int
51-
RESO_SEC: int
52-
RESO_MIN: int
53-
RESO_HR: int
54-
RESO_DAY: int
55-
RESO_MTH: int
56-
RESO_QTR: int
57-
RESO_YR: int
49+
_value_: int
50+
RESO_NS = ...
51+
RESO_US = ...
52+
RESO_MS = ...
53+
RESO_SEC = ...
54+
RESO_MIN = ...
55+
RESO_HR = ...
56+
RESO_DAY = ...
57+
RESO_MTH = ...
58+
RESO_QTR = ...
59+
RESO_YR = ...
5860
def __lt__(self, other: Resolution) -> bool: ...
5961
def __ge__(self, other: Resolution) -> bool: ...
6062
@property
@@ -67,17 +69,18 @@ class Resolution(Enum):
6769
def attr_abbrev(self) -> str: ...
6870

6971
class NpyDatetimeUnit(Enum):
70-
NPY_FR_Y: int
71-
NPY_FR_M: int
72-
NPY_FR_W: int
73-
NPY_FR_D: int
74-
NPY_FR_h: int
75-
NPY_FR_m: int
76-
NPY_FR_s: int
77-
NPY_FR_ms: int
78-
NPY_FR_us: int
79-
NPY_FR_ns: int
80-
NPY_FR_ps: int
81-
NPY_FR_fs: int
82-
NPY_FR_as: int
83-
NPY_FR_GENERIC: int
72+
_value_: int
73+
NPY_FR_Y = ...
74+
NPY_FR_M = ...
75+
NPY_FR_W = ...
76+
NPY_FR_D = ...
77+
NPY_FR_h = ...
78+
NPY_FR_m = ...
79+
NPY_FR_s = ...
80+
NPY_FR_ms = ...
81+
NPY_FR_us = ...
82+
NPY_FR_ns = ...
83+
NPY_FR_ps = ...
84+
NPY_FR_fs = ...
85+
NPY_FR_as = ...
86+
NPY_FR_GENERIC = ...

pandas/_testing/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ class SubclassedDataFrame(DataFrame):
348348
def _constructor(self):
349349
return lambda *args, **kwargs: SubclassedDataFrame(*args, **kwargs)
350350

351+
# error: Cannot override writeable attribute with read-only property
351352
@property
352-
def _constructor_sliced(self):
353+
def _constructor_sliced(self): # type: ignore[override]
353354
return lambda *args, **kwargs: SubclassedSeries(*args, **kwargs)
354355

355356

pandas/_testing/_io.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def round_trip_pathlib(writer, reader, path: str | None = None):
8181
if path is None:
8282
path = "___pathlib___"
8383
with ensure_clean(path) as path:
84-
writer(Path(path)) # type: ignore[arg-type]
85-
obj = reader(Path(path)) # type: ignore[arg-type]
84+
writer(Path(path))
85+
obj = reader(Path(path))
8686
return obj
8787

8888

89-
def write_to_compressed(compression, path, data, dest: str = "test") -> None:
89+
def write_to_compressed(compression, path: str, data, dest: str = "test") -> None:
9090
"""
9191
Write data to a compressed file.
9292
@@ -138,5 +138,9 @@ def write_to_compressed(compression, path, data, dest: str = "test") -> None:
138138
else:
139139
raise ValueError(f"Unrecognized compression type: {compression}")
140140

141-
with compress_method(path, mode=mode) as f:
141+
# error: No overload variant of "ZipFile" matches argument types "str", "str"
142+
# error: No overload variant of "BZ2File" matches argument types "str", "str"
143+
# error: Argument "mode" to "TarFile" has incompatible type "str";
144+
# expected "Literal['r', 'a', 'w', 'x']
145+
with compress_method(path, mode=mode) as f: # type: ignore[call-overload, arg-type]
142146
getattr(f, method)(*args)

pandas/core/algorithms.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _reconstruct_data(
216216
values = cls._from_sequence(values, dtype=dtype) # type: ignore[assignment]
217217

218218
else:
219-
values = values.astype(dtype, copy=False) # type: ignore[assignment]
219+
values = values.astype(dtype, copy=False)
220220

221221
return values
222222

@@ -904,7 +904,10 @@ def value_counts_internal(
904904
.size()
905905
)
906906
result.index.names = values.names
907-
counts = result._values
907+
# error: Incompatible types in assignment (expression has type
908+
# "ndarray[Any, Any] | DatetimeArray | TimedeltaArray | PeriodArray | Any",
909+
# variable has type "ndarray[tuple[int, ...], dtype[Any]]")
910+
counts = result._values # type: ignore[assignment]
908911

909912
else:
910913
values = _ensure_arraylike(values, func_name="value_counts")
@@ -1311,7 +1314,7 @@ def searchsorted(
13111314
_diff_special = {"float64", "float32", "int64", "int32", "int16", "int8"}
13121315

13131316

1314-
def diff(arr, n: int, axis: AxisInt = 0):
1317+
def diff(arr, n: int | float | np.integer, axis: AxisInt = 0):
13151318
"""
13161319
difference of n between self,
13171320
analogous to s-s.shift(n)
@@ -1400,7 +1403,7 @@ def diff(arr, n: int, axis: AxisInt = 0):
14001403
if arr.dtype.name in _diff_special:
14011404
# TODO: can diff_2d dtype specialization troubles be fixed by defining
14021405
# out_arr inside diff_2d?
1403-
algos.diff_2d(arr, out_arr, n, axis, datetimelike=is_timedelta)
1406+
algos.diff_2d(arr, out_arr, int(n), axis, datetimelike=is_timedelta)
14041407
else:
14051408
# To keep mypy happy, _res_indexer is a list while res_indexer is
14061409
# a tuple, ditto for lag_indexer.

pandas/core/apply.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ def agg_or_apply_dict_like(
16451645
assert op_name in ["agg", "apply"]
16461646

16471647
obj = self.obj
1648-
kwargs = {}
1648+
kwargs: dict[str, Any] = {}
16491649
if op_name == "apply":
16501650
by_row = "_compat" if self.by_row else False
16511651
kwargs.update({"by_row": by_row})
@@ -2012,7 +2012,8 @@ def _managle_lambda_list(aggfuncs: Sequence[Any]) -> Sequence[Any]:
20122012
for aggfunc in aggfuncs:
20132013
if com.get_callable_name(aggfunc) == "<lambda>":
20142014
aggfunc = partial(aggfunc)
2015-
aggfunc.__name__ = f"<lambda_{i}>"
2015+
# error: "partial[Any]" has no attribute "__name__"; maybe "__new__"?
2016+
aggfunc.__name__ = f"<lambda_{i}>" # type: ignore[attr-defined]
20162017
i += 1
20172018
mangled_aggfuncs.append(aggfunc)
20182019

pandas/core/array_algos/quantile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _nanquantile(
196196
# Caller is responsible for ensuring mask shape match
197197
assert mask.shape == values.shape
198198
result = [
199-
_nanquantile_1d(val, m, qs, na_value, interpolation=interpolation) # type: ignore[arg-type]
199+
_nanquantile_1d(val, m, qs, na_value, interpolation=interpolation)
200200
for (val, m) in zip(list(values), list(mask))
201201
]
202202
if values.dtype.kind == "f":

pandas/core/arrays/_mixins.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def method(self, *args, **kwargs):
8888
return cast(F, method)
8989

9090

91-
# error: Definition of "delete/ravel/T/repeat/copy" in base class "NDArrayBacked"
92-
# is incompatible with definition in base class "ExtensionArray"
93-
class NDArrayBackedExtensionArray(NDArrayBacked, ExtensionArray): # type: ignore[misc]
91+
class NDArrayBackedExtensionArray(NDArrayBacked, ExtensionArray):
9492
"""
9593
ExtensionArray that is backed by a single NumPy ndarray.
9694
"""

pandas/core/arrays/boolean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def _coerce_to_array(
368368
assert dtype == "boolean"
369369
return coerce_to_array(value, copy=copy)
370370

371-
def _logical_method(self, other, op): # type: ignore[override]
371+
def _logical_method(self, other, op):
372372
assert op.__name__ in {"or_", "ror_", "and_", "rand_", "xor", "rxor"}
373373
other_is_scalar = lib.is_scalar(other)
374374
mask = None

0 commit comments

Comments
 (0)