Skip to content

Update mypy version from 1.11.2 to 1.13.0 #60260

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 33 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3bd4425
Update mypy version from 1.11.2 to 1.13.0
dl-lim Nov 9, 2024
3012424
Removed type ignores
nvasilev Nov 9, 2024
bafc3fa
Correct typing error
ofsouzap Nov 9, 2024
ab4b1e0
Merge pull request #1 from nvasilev/update_mypy
dl-lim Nov 9, 2024
950d657
Merge pull request #2 from ofsouzap/my-typing-fixes
dl-lim Nov 9, 2024
e72632a
Removed a missed type ignore
nvasilev Nov 9, 2024
f6b30d3
nanops typing fix
ofsouzap Nov 9, 2024
160d290
Merge pull request #3 from nvasilev/update_mypy
dl-lim Nov 9, 2024
021cc5a
Merge pull request #4 from ofsouzap/my-typing-fixes
dl-lim Nov 9, 2024
03b51af
Fix indexing typing error
ofsouzap Nov 9, 2024
3c75b7f
added type ignore to _core.py
pyfra Nov 9, 2024
500f006
Merge pull request #5 from ofsouzap/my-typing-fixes
dl-lim Nov 9, 2024
a36a34e
add type ignore to column types
YasithDSL Nov 9, 2024
bcff1ae
Merge branch 'update_mypy' into fix_column_typeerror
YasithDSL Nov 9, 2024
cbe1a9c
Merge remote-tracking branch 'dl/update_mypy' into fix_column_typeerror
YasithDSL Nov 9, 2024
2190f91
added type ignore in _get_common_dtype in dtypes.py
pyfra Nov 9, 2024
4025929
Merge pull request #9 from pyfra/new_err_mypy
dl-lim Nov 9, 2024
1979cb5
Merge pull request #11 from YasithDSL/fix_column_typeerror
dl-lim Nov 9, 2024
5e2f18b
type ignore common.py
shengjie2013 Nov 9, 2024
73f0222
Merge pull request #12 from shengjie2013/typeignore-common
dl-lim Nov 9, 2024
1a4cd40
Add type ignore for call-overload
YasithDSL Nov 9, 2024
12aa2c8
pre-commit
dl-lim Nov 9, 2024
c1d7a57
fix line too long
shengjie2013 Nov 9, 2024
cb1e59d
Merge remote-tracking branch 'dl/update_mypy' into call_overload_err
YasithDSL Nov 9, 2024
034d392
Merge pull request #14 from shengjie2013/typeignore-common
dl-lim Nov 9, 2024
1ef6691
pre-commit
dl-lim Nov 9, 2024
f77a81b
Remove unused ignore
YasithDSL Nov 9, 2024
2a8019b
Fixed type:ignore from type-arg to type-var
nvasilev Nov 9, 2024
65dd644
Merge pull request #16 from nvasilev/update_mypy
dl-lim Nov 9, 2024
685e86f
Merge pull request #17 from YasithDSL/call_overload_err
dl-lim Nov 9, 2024
a6a6dbf
Correct typing fix
ofsouzap Nov 9, 2024
4f838b6
Formatting fixes
ofsouzap Nov 9, 2024
54ce0a2
Merge pull request #18 from ofsouzap/my-typing-fixes
dl-lim Nov 9, 2024
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 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
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8024,7 +8024,7 @@ def asof(self, where, subset=None):
np.nan, index=self.columns, name=where[0]
)

locs = self.index.asof_locs(where, ~(nulls._values))
locs = self.index.asof_locs(where, ~cast("DataFrame", nulls._values))

# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you comment in PR a example returning an array

Copy link
Contributor

@ofsouzap ofsouzap Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the following code would be an example of when the function would return an array, and not a float:

import pandas as pd
import numpy as np

pd.core.nanops.nanmedian(
  np.array([
    [1, 2, 3],
    [2, 3, 4]
  ],
  axis=1)
)

This code would output,

array([2., 3.])

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