From d0c911511a439fd9f0becf752e37e5f96944a50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 17 Mar 2022 22:19:41 -0400 Subject: [PATCH] CI: bump mypy&pyright --- .github/workflows/code-checks.yml | 2 +- .pre-commit-config.yaml | 2 +- doc/source/whatsnew/v1.5.0.rst | 2 +- environment.yml | 2 +- pandas/core/arrays/sparse/array.py | 3 +-- pandas/core/computation/ops.py | 3 ++- pandas/core/generic.py | 15 ++++++++++++--- pandas/core/indexes/base.py | 6 +++++- pandas/io/formats/style.py | 12 ++++++++++-- requirements-dev.txt | 2 +- 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index 58bef05940af1..f32fed3b3ee68 100644 --- a/.github/workflows/code-checks.yml +++ b/.github/workflows/code-checks.yml @@ -74,7 +74,7 @@ jobs: - name: Install pyright # note: keep version in sync with .pre-commit-config.yaml - run: npm install -g pyright@1.1.212 + run: npm install -g pyright@1.1.230 - name: Build Pandas id: build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c58ccb52f9e5..aeb49c2b1a545 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -85,7 +85,7 @@ repos: types: [python] stages: [manual] # note: keep version in sync with .github/workflows/code-checks.yml - additional_dependencies: ['pyright@1.1.212'] + additional_dependencies: ['pyright@1.1.230'] - repo: local hooks: - id: flake8-rst diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index b1caeaf5e4726..b90a877012e6f 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -177,7 +177,7 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | Package | Minimum Version | Required | Changed | +=================+=================+==========+=========+ -| mypy (dev) | 0.931 | | X | +| mypy (dev) | 0.941 | | X | +-----------------+-----------------+----------+---------+ diff --git a/environment.yml b/environment.yml index 2c6a6c95569d6..5402be3d4a00b 100644 --- a/environment.yml +++ b/environment.yml @@ -24,7 +24,7 @@ dependencies: - flake8-bugbear=21.3.2 # used by flake8, find likely bugs - flake8-comprehensions=3.7.0 # used by flake8, linting of unnecessary comprehensions - isort>=5.2.1 # check that imports are in the right order - - mypy=0.931 + - mypy=0.941 - pre-commit>=2.9.2 - pycodestyle # used by flake8 - pyupgrade diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 15ec1006b4f80..c2a13961687fd 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -774,8 +774,7 @@ def fillna( elif method is not None: msg = "fillna with 'method' requires high memory usage." warnings.warn(msg, PerformanceWarning) - # Need type annotation for "new_values" [var-annotated] - new_values = np.asarray(self) # type: ignore[var-annotated] + new_values = np.asarray(self) # interpolate_2d modifies new_values inplace interpolate_2d(new_values, method=method, limit=limit) return type(self)(new_values, fill_value=self.fill_value) diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index 0109e0d2add11..9c54065de0353 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -580,7 +580,8 @@ def __init__(self, op: str, operand) -> None: def __call__(self, env): operand = self.operand(env) - return self.func(operand) + # error: Cannot call function of unknown type + return self.func(operand) # type: ignore[operator] def __repr__(self) -> str: return pprint_thing(f"{self.op}({self.operand})") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d00a2778848ae..983fb8f0edf12 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1481,9 +1481,15 @@ def equals(self, other: object) -> bool_t: def __neg__(self): def blk_func(values: ArrayLike): if is_bool_dtype(values.dtype): - return operator.inv(values) + # error: Argument 1 to "inv" has incompatible type "Union + # [ExtensionArray, ndarray[Any, Any]]"; expected + # "_SupportsInversion[ndarray[Any, dtype[bool_]]]" + return operator.inv(values) # type: ignore[arg-type] else: - return operator.neg(values) + # error: Argument 1 to "neg" has incompatible type "Union + # [ExtensionArray, ndarray[Any, Any]]"; expected + # "_SupportsNeg[ndarray[Any, dtype[Any]]]" + return operator.neg(values) # type: ignore[arg-type] new_data = self._mgr.apply(blk_func) res = self._constructor(new_data) @@ -1495,7 +1501,10 @@ def blk_func(values: ArrayLike): if is_bool_dtype(values.dtype): return values.copy() else: - return operator.pos(values) + # error: Argument 1 to "pos" has incompatible type "Union + # [ExtensionArray, ndarray[Any, Any]]"; expected + # "_SupportsPos[ndarray[Any, dtype[Any]]]" + return operator.pos(values) # type: ignore[arg-type] new_data = self._mgr.apply(blk_func) res = self._constructor(new_data) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 37fee7058f902..ab6e1c47057eb 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4088,7 +4088,11 @@ def _get_nearest_indexer( op = operator.lt if self.is_monotonic_increasing else operator.le indexer = np.where( - op(left_distances, right_distances) | (right_indexer == -1), + # error: Argument 1&2 has incompatible type "Union[ExtensionArray, + # ndarray[Any, Any]]"; expected "Union[SupportsDunderLE, + # SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]" + op(left_distances, right_distances) # type: ignore[arg-type] + | (right_indexer == -1), left_indexer, right_indexer, ) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 764787dd962e9..a3899fb880e6c 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -3875,14 +3875,22 @@ def _highlight_between( ) g_left = ( - ops[0](data, left) + # error: Argument 2 to "ge" has incompatible type "Union[str, float, + # Period, Timedelta, Interval[Any], datetime64, timedelta64, datetime, + # Sequence[Any], ndarray[Any, Any], NDFrame]"; expected "Union + # [SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]" + ops[0](data, left) # type: ignore[arg-type] if left is not None else np.full(data.shape, True, dtype=bool) ) if isinstance(g_left, (DataFrame, Series)): g_left = g_left.where(pd.notna(g_left), False) l_right = ( - ops[1](data, right) + # error: Argument 2 to "le" has incompatible type "Union[str, float, + # Period, Timedelta, Interval[Any], datetime64, timedelta64, datetime, + # Sequence[Any], ndarray[Any, Any], NDFrame]"; expected "Union + # [SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]" + ops[1](data, right) # type: ignore[arg-type] if right is not None else np.full(data.shape, True, dtype=bool) ) diff --git a/requirements-dev.txt b/requirements-dev.txt index 94a1d344b4849..c671dc08a263e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,7 +12,7 @@ flake8==4.0.1 flake8-bugbear==21.3.2 flake8-comprehensions==3.7.0 isort>=5.2.1 -mypy==0.931 +mypy==0.941 pre-commit>=2.9.2 pycodestyle pyupgrade