Skip to content

Commit 4fcee0e

Browse files
authored
Update mypy version from 1.11.2 to 1.13.0 (#60260)
1 parent 084b199 commit 4fcee0e

File tree

14 files changed

+39
-35
lines changed

14 files changed

+39
-35
lines changed

environment.yml

+1-1
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.11.2 # pre-commit uses locally installed mypy
80+
- mypy=1.13.0 # pre-commit uses locally installed mypy
8181
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
8282
- pre-commit>=4.0.1
8383

pandas/core/computation/ops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
class Term:
7777
def __new__(cls, name, env, side=None, encoding=None):
7878
klass = Constant if not isinstance(name, str) else cls
79-
# error: Argument 2 for "super" not an instance of argument 1
80-
supr_new = super(Term, klass).__new__ # type: ignore[misc]
79+
supr_new = super(Term, klass).__new__
8180
return supr_new(klass)
8281

8382
is_local: bool

pandas/core/dtypes/dtypes.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2130,9 +2130,11 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
21302130
PerformanceWarning,
21312131
stacklevel=find_stack_level(),
21322132
)
2133-
21342133
np_dtypes = (x.subtype if isinstance(x, SparseDtype) else x for x in dtypes)
2135-
return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value)
2134+
# error: Argument 1 to "np_find_common_type" has incompatible type
2135+
# "*Generator[Any | dtype[Any] | ExtensionDtype, None, None]";
2136+
# expected "dtype[Any]" [arg-type]
2137+
return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value) # type: ignore [arg-type]
21362138

21372139

21382140
@register_extension_dtype

pandas/core/generic.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8024,7 +8024,9 @@ def asof(self, where, subset=None):
80248024
np.nan, index=self.columns, name=where[0]
80258025
)
80268026

8027-
locs = self.index.asof_locs(where, ~(nulls._values))
8027+
# error: Unsupported operand type for
8028+
# ~ ("ExtensionArray | ndarray[Any, Any] | Any")
8029+
locs = self.index.asof_locs(where, ~nulls._values) # type: ignore[operator]
80288030

80298031
# mask the missing
80308032
mask = locs == -1

pandas/core/indexes/interval.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ def _maybe_convert_i8(self, key):
558558
left = self._maybe_convert_i8(key.left)
559559
right = self._maybe_convert_i8(key.right)
560560
constructor = Interval if scalar else IntervalIndex.from_arrays
561-
# error: "object" not callable
562-
return constructor(left, right, closed=self.closed) # type: ignore[operator]
561+
return constructor(left, right, closed=self.closed)
563562

564563
if scalar:
565564
# Timestamp/Timedelta

pandas/core/indexing.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,9 @@ def __setitem__(self, key, value) -> None:
914914
indexer = self._get_setitem_indexer(key)
915915
self._has_valid_setitem_indexer(key)
916916

917-
iloc = self if self.name == "iloc" else self.obj.iloc
917+
iloc: _iLocIndexer = (
918+
cast("_iLocIndexer", self) if self.name == "iloc" else self.obj.iloc
919+
)
918920
iloc._setitem_with_indexer(indexer, value, self.name)
919921

920922
def _validate_key(self, key, axis: AxisInt) -> None:

pandas/core/missing.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,10 @@ def func(yvalues: np.ndarray) -> None:
413413
**kwargs,
414414
)
415415

416-
# error: Argument 1 to "apply_along_axis" has incompatible type
417-
# "Callable[[ndarray[Any, Any]], None]"; expected "Callable[...,
418-
# Union[_SupportsArray[dtype[<nothing>]], Sequence[_SupportsArray
419-
# [dtype[<nothing>]]], Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]],
420-
# Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]],
421-
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]]"
422-
np.apply_along_axis(func, axis, data) # type: ignore[arg-type]
416+
# error: No overload variant of "apply_along_axis" matches
417+
# argument types "Callable[[ndarray[Any, Any]], None]",
418+
# "int", "ndarray[Any, Any]"
419+
np.apply_along_axis(func, axis, data) # type: ignore[call-overload]
423420

424421

425422
def _index_to_interp_indices(index: Index, method: str) -> np.ndarray:

pandas/core/nanops.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,9 @@ def nanmean(
726726

727727

728728
@bottleneck_switch()
729-
def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=None):
729+
def nanmedian(
730+
values: np.ndarray, *, axis: AxisInt | None = None, skipna: bool = True, mask=None
731+
) -> float | np.ndarray:
730732
"""
731733
Parameters
732734
----------
@@ -738,7 +740,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
738740
739741
Returns
740742
-------
741-
result : float
743+
result : float | ndarray
742744
Unless input is a float array, in which case use the same
743745
precision as the input array.
744746
@@ -758,7 +760,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
758760
# cases we never need to set NaN to the masked values
759761
using_nan_sentinel = values.dtype.kind == "f" and mask is None
760762

761-
def get_median(x, _mask=None):
763+
def get_median(x: np.ndarray, _mask=None):
762764
if _mask is None:
763765
_mask = notna(x)
764766
else:
@@ -794,6 +796,8 @@ def get_median(x, _mask=None):
794796

795797
notempty = values.size
796798

799+
res: float | np.ndarray
800+
797801
# an array from a frame
798802
if values.ndim > 1 and axis is not None:
799803
# there's a non-empty array to apply over otherwise numpy raises

pandas/io/common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,10 @@ def get_handle(
910910
or not hasattr(handle, "seekable")
911911
):
912912
handle = _IOWrapper(handle)
913-
# error: Argument 1 to "TextIOWrapper" has incompatible type
914-
# "_IOWrapper"; expected "IO[bytes]"
913+
# error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot
914+
# be "_IOWrapper | BaseBuffer" [type-var]
915915
handle = TextIOWrapper(
916-
handle, # type: ignore[arg-type]
916+
handle, # type: ignore[type-var]
917917
encoding=ioargs.encoding,
918918
errors=errors,
919919
newline="",

pandas/plotting/_core.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,9 @@ def __call__(self, *args, **kwargs):
10381038
label_name = label_kw or y
10391039
data.name = label_name
10401040
else:
1041-
match = is_list_like(label_kw) and len(label_kw) == len(y)
1041+
# error: Argument 1 to "len" has incompatible type "Any | bool";
1042+
# expected "Sized" [arg-type]
1043+
match = is_list_like(label_kw) and len(label_kw) == len(y) # type: ignore[arg-type]
10421044
if label_kw and not match:
10431045
raise ValueError(
10441046
"label should be list-like and same length as y"

pandas/plotting/_matplotlib/boxplot.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ def _make_plot(self, fig: Figure) -> None:
198198
else self.data
199199
)
200200

201-
# error: Argument "data" to "_iter_data" of "MPLPlot" has
202-
# incompatible type "object"; expected "DataFrame |
203-
# dict[Hashable, Series | DataFrame]"
204-
for i, (label, y) in enumerate(self._iter_data(data=data)): # type: ignore[arg-type]
201+
for i, (label, y) in enumerate(self._iter_data(data=data)):
205202
ax = self._get_ax(i)
206203
kwds = self.kwds.copy()
207204

pandas/plotting/_matplotlib/hist.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ def _make_plot(self, fig: Figure) -> None:
137137
if self.by is not None
138138
else self.data
139139
)
140-
141-
# error: Argument "data" to "_iter_data" of "MPLPlot" has incompatible
142-
# type "object"; expected "DataFrame | dict[Hashable, Series | DataFrame]"
143-
for i, (label, y) in enumerate(self._iter_data(data=data)): # type: ignore[arg-type]
140+
for i, (label, y) in enumerate(self._iter_data(data=data)):
144141
ax = self._get_ax(i)
145142

146143
kwds = self.kwds.copy()

pandas/tests/io/test_sql.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,17 @@ def types_table_metadata(dialect: str):
237237
"types",
238238
metadata,
239239
Column("TextCol", TEXT),
240-
Column("DateCol", date_type),
240+
# error: Cannot infer type argument 1 of "Column"
241+
Column("DateCol", date_type), # type: ignore[misc]
241242
Column("IntDateCol", Integer),
242243
Column("IntDateOnlyCol", Integer),
243244
Column("FloatCol", Float),
244245
Column("IntCol", Integer),
245-
Column("BoolCol", bool_type),
246+
# error: Cannot infer type argument 1 of "Column"
247+
Column("BoolCol", bool_type), # type: ignore[misc]
246248
Column("IntColWithNull", Integer),
247-
Column("BoolColWithNull", bool_type),
249+
# error: Cannot infer type argument 1 of "Column"
250+
Column("BoolColWithNull", bool_type), # type: ignore[misc]
248251
)
249252
return types
250253

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ moto
5454
flask
5555
asv>=0.6.1
5656
flake8==7.1.0
57-
mypy==1.11.2
57+
mypy==1.13.0
5858
tokenize-rt
5959
pre-commit>=4.0.1
6060
gitpython

0 commit comments

Comments
 (0)