Skip to content

Commit

Permalink
TYP: mypy 0.930 and pyright 1.1.200 (pandas-dev#45067)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoertwein authored Dec 27, 2021
1 parent eeff2b0 commit 6bc6366
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

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

- name: Build Pandas
uses: ./.github/actions/build_pandas
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ repos:
types: [python]
stages: [manual]
# note: keep version in sync with .github/workflows/ci.yml
additional_dependencies: ['[email protected].171']
additional_dependencies: ['[email protected].200']
- repo: local
hooks:
- id: flake8-rst
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ If installed, we now require:
+-----------------+-----------------+----------+---------+
| pytest (dev) | 6.0 | | |
+-----------------+-----------------+----------+---------+
| mypy (dev) | 0.920 | | X |
| mypy (dev) | 0.930 | | X |
+-----------------+-----------------+----------+---------+

For `optional libraries <https://pandas.pydata.org/docs/getting_started/install.html>`_ the general recommendation is to use the latest version.
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.920
- mypy=0.930
- pre-commit>=2.9.2
- pycodestyle # used by flake8
- pyupgrade
Expand Down
12 changes: 4 additions & 8 deletions pandas/compat/chainmap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import (
ChainMap,
MutableMapping,
TypeVar,
cast,
)

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

def __setitem__(self, key: _KT, value: _VT) -> None:
for mapping in self.maps:
mutable_mapping = cast(MutableMapping[_KT, _VT], mapping)
if key in mutable_mapping:
mutable_mapping[key] = value
if key in mapping:
mapping[key] = value
return
cast(MutableMapping[_KT, _VT], self.maps[0])[key] = value
self.maps[0][key] = value

def __delitem__(self, key: _KT) -> None:
"""
Expand All @@ -32,8 +29,7 @@ def __delitem__(self, key: _KT) -> None:
If `key` doesn't exist.
"""
for mapping in self.maps:
mutable_mapping = cast(MutableMapping[_KT, _VT], mapping)
if key in mapping:
del mutable_mapping[key]
del mapping[key]
return
raise KeyError(key)
10 changes: 2 additions & 8 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:

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

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

def take(
self: NDArrayBackedExtensionArrayT,
Expand Down Expand Up @@ -276,13 +274,9 @@ def __getitem__(
return self._box_func(result)
return self._from_backing_data(result)

# error: Value of type variable "AnyArrayLike" of "extract_array" cannot be
# "Union[int, slice, ndarray]"
# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "Union[int, slice, ndarray]")
key = extract_array( # type: ignore[type-var,assignment]
key, extract_numpy=True
)
key = extract_array(key, extract_numpy=True) # type: ignore[assignment]
key = check_array_indexer(self, key)
result = self._ndarray[key]
if lib.is_scalar(result):
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,10 @@ def _str_map(
mask.view("uint8"),
convert=False,
na_value=na_value,
# error: Value of type variable "_DTypeScalar" of "dtype" cannot be
# "object"
# error: Argument 1 to "dtype" has incompatible type
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected
# "Type[object]"
dtype=np.dtype(dtype), # type: ignore[type-var,arg-type]
dtype=np.dtype(dtype), # type: ignore[arg-type]
)

if not na_value_is_na:
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,10 @@ def _str_map(
mask.view("uint8"),
convert=False,
na_value=na_value,
# error: Value of type variable "_DTypeScalar" of "dtype" cannot be
# "object"
# error: Argument 1 to "dtype" has incompatible type
# "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected
# "Type[object]"
dtype=np.dtype(dtype), # type: ignore[type-var,arg-type]
dtype=np.dtype(dtype), # type: ignore[arg-type]
)

if not na_value_is_na:
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/computation/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ def swapkey(self, old_key: str, new_key: str, new_value=None) -> None:

for mapping in maps:
if old_key in mapping:
# error: Unsupported target for indexed assignment ("Mapping[Any, Any]")
mapping[new_key] = new_value # type: ignore[index]
mapping[new_key] = new_value
return

def _get_vars(self, stack, scopes: list[str]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ def __repr__(self) -> str:
return f"{type(self).__name__}({str(self)})"

__setitem__ = __setslice__ = _disabled # type: ignore[assignment]
__delitem__ = __delslice__ = _disabled # type: ignore[assignment]
pop = append = extend = _disabled # type: ignore[assignment]
__delitem__ = __delslice__ = _disabled
pop = append = extend = _disabled
remove = sort = insert = _disabled # type: ignore[assignment]
4 changes: 1 addition & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2154,11 +2154,9 @@ def _factorize_keys(
# variable has type "ExtensionArray")
lk, _ = lk._values_for_factorize()

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

klass: type[libhashtable.Factorizer] | type[libhashtable.Int64Factorizer]
if is_integer_dtype(lk.dtype) and is_integer_dtype(rk.dtype):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ reportImportCycles = false
reportIncompatibleMethodOverride = false
reportIncompatibleVariableOverride = false
reportMissingModuleSource = false
reportMissingParameterType = false
reportMissingTypeArgument = false
reportMissingTypeStubs = false
reportOptionalCall = false
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ flake8==4.0.1
flake8-bugbear==21.3.2
flake8-comprehensions==3.7.0
isort>=5.2.1
mypy==0.920
mypy==0.930
pre-commit>=2.9.2
pycodestyle
pyupgrade
Expand Down

0 comments on commit 6bc6366

Please sign in to comment.