Skip to content

Commit

Permalink
Update mypy version from 1.11.2 to 1.13.0 (#60260)
Browse files Browse the repository at this point in the history
  • Loading branch information
dl-lim authored Nov 9, 2024
1 parent 084b199 commit 4fcee0e
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dependencies:

# code checks
- flake8=7.1.0 # run in subprocess over docstring examples
- mypy=1.11.2 # pre-commit uses locally installed mypy
- mypy=1.13.0 # pre-commit uses locally installed mypy
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
- pre-commit>=4.0.1

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
class Term:
def __new__(cls, name, env, side=None, encoding=None):
klass = Constant if not isinstance(name, str) else cls
# error: Argument 2 for "super" not an instance of argument 1
supr_new = super(Term, klass).__new__ # type: ignore[misc]
supr_new = super(Term, klass).__new__
return supr_new(klass)

is_local: bool
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2130,9 +2130,11 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
PerformanceWarning,
stacklevel=find_stack_level(),
)

np_dtypes = (x.subtype if isinstance(x, SparseDtype) else x for x in dtypes)
return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value)
# error: Argument 1 to "np_find_common_type" has incompatible type
# "*Generator[Any | dtype[Any] | ExtensionDtype, None, None]";
# expected "dtype[Any]" [arg-type]
return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value) # type: ignore [arg-type]


@register_extension_dtype
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8024,7 +8024,9 @@ def asof(self, where, subset=None):
np.nan, index=self.columns, name=where[0]
)

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

# mask the missing
mask = locs == -1
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ def _maybe_convert_i8(self, key):
left = self._maybe_convert_i8(key.left)
right = self._maybe_convert_i8(key.right)
constructor = Interval if scalar else IntervalIndex.from_arrays
# error: "object" not callable
return constructor(left, right, closed=self.closed) # type: ignore[operator]
return constructor(left, right, closed=self.closed)

if scalar:
# Timestamp/Timedelta
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ def __setitem__(self, key, value) -> None:
indexer = self._get_setitem_indexer(key)
self._has_valid_setitem_indexer(key)

iloc = self if self.name == "iloc" else self.obj.iloc
iloc: _iLocIndexer = (
cast("_iLocIndexer", self) if self.name == "iloc" else self.obj.iloc
)
iloc._setitem_with_indexer(indexer, value, self.name)

def _validate_key(self, key, axis: AxisInt) -> None:
Expand Down
11 changes: 4 additions & 7 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,10 @@ def func(yvalues: np.ndarray) -> None:
**kwargs,
)

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


def _index_to_interp_indices(index: Index, method: str) -> np.ndarray:
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ def nanmean(


@bottleneck_switch()
def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=None):
def nanmedian(
values: np.ndarray, *, axis: AxisInt | None = None, skipna: bool = True, mask=None
) -> float | np.ndarray:
"""
Parameters
----------
Expand All @@ -738,7 +740,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
Returns
-------
result : float
result : float | ndarray
Unless input is a float array, in which case use the same
precision as the input array.
Expand All @@ -758,7 +760,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
# cases we never need to set NaN to the masked values
using_nan_sentinel = values.dtype.kind == "f" and mask is None

def get_median(x, _mask=None):
def get_median(x: np.ndarray, _mask=None):
if _mask is None:
_mask = notna(x)
else:
Expand Down Expand Up @@ -794,6 +796,8 @@ def get_median(x, _mask=None):

notempty = values.size

res: float | np.ndarray

# an array from a frame
if values.ndim > 1 and axis is not None:
# there's a non-empty array to apply over otherwise numpy raises
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,10 @@ def get_handle(
or not hasattr(handle, "seekable")
):
handle = _IOWrapper(handle)
# error: Argument 1 to "TextIOWrapper" has incompatible type
# "_IOWrapper"; expected "IO[bytes]"
# error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot
# be "_IOWrapper | BaseBuffer" [type-var]
handle = TextIOWrapper(
handle, # type: ignore[arg-type]
handle, # type: ignore[type-var]
encoding=ioargs.encoding,
errors=errors,
newline="",
Expand Down
4 changes: 3 additions & 1 deletion pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,9 @@ def __call__(self, *args, **kwargs):
label_name = label_kw or y
data.name = label_name
else:
match = is_list_like(label_kw) and len(label_kw) == len(y)
# error: Argument 1 to "len" has incompatible type "Any | bool";
# expected "Sized" [arg-type]
match = is_list_like(label_kw) and len(label_kw) == len(y) # type: ignore[arg-type]
if label_kw and not match:
raise ValueError(
"label should be list-like and same length as y"
Expand Down
5 changes: 1 addition & 4 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ def _make_plot(self, fig: Figure) -> None:
else self.data
)

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

Expand Down
5 changes: 1 addition & 4 deletions pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ def _make_plot(self, fig: Figure) -> None:
if self.by is not None
else self.data
)

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

kwds = self.kwds.copy()
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,17 @@ def types_table_metadata(dialect: str):
"types",
metadata,
Column("TextCol", TEXT),
Column("DateCol", date_type),
# error: Cannot infer type argument 1 of "Column"
Column("DateCol", date_type), # type: ignore[misc]
Column("IntDateCol", Integer),
Column("IntDateOnlyCol", Integer),
Column("FloatCol", Float),
Column("IntCol", Integer),
Column("BoolCol", bool_type),
# error: Cannot infer type argument 1 of "Column"
Column("BoolCol", bool_type), # type: ignore[misc]
Column("IntColWithNull", Integer),
Column("BoolColWithNull", bool_type),
# error: Cannot infer type argument 1 of "Column"
Column("BoolColWithNull", bool_type), # type: ignore[misc]
)
return types

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ moto
flask
asv>=0.6.1
flake8==7.1.0
mypy==1.11.2
mypy==1.13.0
tokenize-rt
pre-commit>=4.0.1
gitpython
Expand Down

0 comments on commit 4fcee0e

Please sign in to comment.