Skip to content

Commit 6bc6366

Browse files
authored
TYP: mypy 0.930 and pyright 1.1.200 (#45067)
1 parent eeff2b0 commit 6bc6366

File tree

13 files changed

+18
-34
lines changed

13 files changed

+18
-34
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555

5656
- name: Install pyright
5757
# note: keep version in sync with .pre-commit-config.yaml
58-
run: npm install -g [email protected].171
58+
run: npm install -g [email protected].200
5959

6060
- name: Build Pandas
6161
uses: ./.github/actions/build_pandas

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ repos:
7878
types: [python]
7979
stages: [manual]
8080
# note: keep version in sync with .github/workflows/ci.yml
81-
additional_dependencies: ['[email protected].171']
81+
additional_dependencies: ['[email protected].200']
8282
- repo: local
8383
hooks:
8484
- id: flake8-rst

doc/source/whatsnew/v1.4.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ If installed, we now require:
398398
+-----------------+-----------------+----------+---------+
399399
| pytest (dev) | 6.0 | | |
400400
+-----------------+-----------------+----------+---------+
401-
| mypy (dev) | 0.920 | | X |
401+
| mypy (dev) | 0.930 | | X |
402402
+-----------------+-----------------+----------+---------+
403403

404404
For `optional libraries <https://pandas.pydata.org/docs/getting_started/install.html>`_ the general recommendation is to use the latest version.

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
- flake8-bugbear=21.3.2 # used by flake8, find likely bugs
2525
- flake8-comprehensions=3.7.0 # used by flake8, linting of unnecessary comprehensions
2626
- isort>=5.2.1 # check that imports are in the right order
27-
- mypy=0.920
27+
- mypy=0.930
2828
- pre-commit>=2.9.2
2929
- pycodestyle # used by flake8
3030
- pyupgrade

pandas/compat/chainmap.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from typing import (
22
ChainMap,
3-
MutableMapping,
43
TypeVar,
5-
cast,
64
)
75

86
_KT = TypeVar("_KT")
@@ -18,11 +16,10 @@ class DeepChainMap(ChainMap[_KT, _VT]):
1816

1917
def __setitem__(self, key: _KT, value: _VT) -> None:
2018
for mapping in self.maps:
21-
mutable_mapping = cast(MutableMapping[_KT, _VT], mapping)
22-
if key in mutable_mapping:
23-
mutable_mapping[key] = value
19+
if key in mapping:
20+
mapping[key] = value
2421
return
25-
cast(MutableMapping[_KT, _VT], self.maps[0])[key] = value
22+
self.maps[0][key] = value
2623

2724
def __delitem__(self, key: _KT) -> None:
2825
"""
@@ -32,8 +29,7 @@ def __delitem__(self, key: _KT) -> None:
3229
If `key` doesn't exist.
3330
"""
3431
for mapping in self.maps:
35-
mutable_mapping = cast(MutableMapping[_KT, _VT], mapping)
3632
if key in mapping:
37-
del mutable_mapping[key]
33+
del mapping[key]
3834
return
3935
raise KeyError(key)

pandas/core/arrays/_mixins.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:
138138

139139
return TimedeltaArray(arr.view("i8"), dtype=dtype)
140140

141-
# error: Incompatible return value type (got "ndarray", expected
142-
# "ExtensionArray")
143141
# error: Argument "dtype" to "view" of "_ArrayOrScalarCommon" has incompatible
144142
# type "Union[ExtensionDtype, dtype[Any]]"; expected "Union[dtype[Any], None,
145143
# type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int,
146144
# Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
147-
return arr.view(dtype=dtype) # type: ignore[return-value,arg-type]
145+
return arr.view(dtype=dtype) # type: ignore[arg-type]
148146

149147
def take(
150148
self: NDArrayBackedExtensionArrayT,
@@ -276,13 +274,9 @@ def __getitem__(
276274
return self._box_func(result)
277275
return self._from_backing_data(result)
278276

279-
# error: Value of type variable "AnyArrayLike" of "extract_array" cannot be
280-
# "Union[int, slice, ndarray]"
281277
# error: Incompatible types in assignment (expression has type "ExtensionArray",
282278
# variable has type "Union[int, slice, ndarray]")
283-
key = extract_array( # type: ignore[type-var,assignment]
284-
key, extract_numpy=True
285-
)
279+
key = extract_array(key, extract_numpy=True) # type: ignore[assignment]
286280
key = check_array_indexer(self, key)
287281
result = self._ndarray[key]
288282
if lib.is_scalar(result):

pandas/core/arrays/string_.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,10 @@ def _str_map(
545545
mask.view("uint8"),
546546
convert=False,
547547
na_value=na_value,
548-
# error: Value of type variable "_DTypeScalar" of "dtype" cannot be
549-
# "object"
550548
# error: Argument 1 to "dtype" has incompatible type
551549
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected
552550
# "Type[object]"
553-
dtype=np.dtype(dtype), # type: ignore[type-var,arg-type]
551+
dtype=np.dtype(dtype), # type: ignore[arg-type]
554552
)
555553

556554
if not na_value_is_na:

pandas/core/arrays/string_arrow.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,10 @@ def _str_map(
675675
mask.view("uint8"),
676676
convert=False,
677677
na_value=na_value,
678-
# error: Value of type variable "_DTypeScalar" of "dtype" cannot be
679-
# "object"
680678
# error: Argument 1 to "dtype" has incompatible type
681679
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected
682680
# "Type[object]"
683-
dtype=np.dtype(dtype), # type: ignore[type-var,arg-type]
681+
dtype=np.dtype(dtype), # type: ignore[arg-type]
684682
)
685683

686684
if not na_value_is_na:

pandas/core/computation/scope.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ def swapkey(self, old_key: str, new_key: str, new_value=None) -> None:
232232

233233
for mapping in maps:
234234
if old_key in mapping:
235-
# error: Unsupported target for indexed assignment ("Mapping[Any, Any]")
236-
mapping[new_key] = new_value # type: ignore[index]
235+
mapping[new_key] = new_value
237236
return
238237

239238
def _get_vars(self, stack, scopes: list[str]) -> None:

pandas/core/indexes/frozen.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ def __repr__(self) -> str:
105105
return f"{type(self).__name__}({str(self)})"
106106

107107
__setitem__ = __setslice__ = _disabled # type: ignore[assignment]
108-
__delitem__ = __delslice__ = _disabled # type: ignore[assignment]
109-
pop = append = extend = _disabled # type: ignore[assignment]
108+
__delitem__ = __delslice__ = _disabled
109+
pop = append = extend = _disabled
110110
remove = sort = insert = _disabled # type: ignore[assignment]

pandas/core/reshape/merge.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2154,11 +2154,9 @@ def _factorize_keys(
21542154
# variable has type "ExtensionArray")
21552155
lk, _ = lk._values_for_factorize()
21562156

2157-
# error: Incompatible types in assignment (expression has type
2158-
# "ndarray", variable has type "ExtensionArray")
21592157
# error: Item "ndarray" of "Union[Any, ndarray]" has no attribute
21602158
# "_values_for_factorize"
2161-
rk, _ = rk._values_for_factorize() # type: ignore[union-attr,assignment]
2159+
rk, _ = rk._values_for_factorize() # type: ignore[union-attr]
21622160

21632161
klass: type[libhashtable.Factorizer] | type[libhashtable.Int64Factorizer]
21642162
if is_integer_dtype(lk.dtype) and is_integer_dtype(rk.dtype):

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ reportImportCycles = false
159159
reportIncompatibleMethodOverride = false
160160
reportIncompatibleVariableOverride = false
161161
reportMissingModuleSource = false
162+
reportMissingParameterType = false
162163
reportMissingTypeArgument = false
163164
reportMissingTypeStubs = false
164165
reportOptionalCall = false

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ flake8==4.0.1
1212
flake8-bugbear==21.3.2
1313
flake8-comprehensions==3.7.0
1414
isort>=5.2.1
15-
mypy==0.920
15+
mypy==0.930
1616
pre-commit>=2.9.2
1717
pycodestyle
1818
pyupgrade

0 commit comments

Comments
 (0)