From 11887efa05c4c2a2c902729dfc53281028b5903f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 30 Apr 2022 09:07:11 -0400 Subject: [PATCH 1/5] TYP/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/_config/localization.py | 4 +++- pandas/_libs/tslibs/timestamps.pyi | 2 +- pandas/io/parsers/base_parser.py | 25 ++++++++----------------- requirements-dev.txt | 2 +- 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index d4a2bedcfba1a..6c3d34e5fabcd 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.245 + run: npm install -g pyright@1.1.246 - name: Build Pandas id: build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fac09fcf70511..41c94024b79f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,7 +89,7 @@ repos: types: [python] stages: [manual] # note: keep version in sync with .github/workflows/code-checks.yml - additional_dependencies: ['pyright@1.1.245'] + additional_dependencies: ['pyright@1.1.246'] - 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 9f1c4755bc54f..128fd68674f96 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -360,7 +360,7 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | Package | Minimum Version | Required | Changed | +=================+=================+==========+=========+ -| mypy (dev) | 0.941 | | X | +| mypy (dev) | 0.950 | | X | +-----------------+-----------------+----------+---------+ diff --git a/environment.yml b/environment.yml index dc3cba3be2132..b4710e252384c 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.941 + - mypy=0.950 - pre-commit>=2.9.2 - pycodestyle # used by flake8 - pyupgrade diff --git a/pandas/_config/localization.py b/pandas/_config/localization.py index 2a487fa4b6877..2e1ef31033d71 100644 --- a/pandas/_config/localization.py +++ b/pandas/_config/localization.py @@ -45,7 +45,9 @@ def set_locale( locale.setlocale(lc_var, new_locale) normalized_locale = locale.getlocale() if all(x is not None for x in normalized_locale): - yield ".".join(normalized_locale) + # error: Argument 1 to "join" of "str" has incompatible type + # "Tuple[Optional[str], Optional[str]]"; expected "Iterable[str]" + yield ".".join(normalized_locale) # type: ignore[arg-type] else: yield new_locale finally: diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 13daba5cfcbdf..61deac3f3e1c5 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -123,7 +123,7 @@ class Timestamp(datetime): microsecond: int = ..., tzinfo: _tzinfo | None = ..., fold: int = ..., - ) -> datetime: ... + ) -> Timestamp: ... def astimezone(self: _DatetimeT, tz: _tzinfo | None = ...) -> _DatetimeT: ... def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 2851ea36c8a33..10fe6399bb81d 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -7,6 +7,7 @@ from enum import Enum import itertools from typing import ( + Any, Callable, DefaultDict, Hashable, @@ -1027,26 +1028,14 @@ def _get_empty_meta( # Convert `dtype` to a defaultdict of some kind. # This will enable us to write `dtype[col_name]` # without worrying about KeyError issues later on. + dtype_dict: DefaultDict[Hashable, Any] if not is_dict_like(dtype): # if dtype == None, default will be object. default_dtype = dtype or object - # error: Argument 1 to "defaultdict" has incompatible type "Callable[[], - # Union[ExtensionDtype, str, dtype[Any], Type[object], Dict[Hashable, - # Union[ExtensionDtype, Union[str, dtype[Any]], Type[str], Type[float], - # Type[int], Type[complex], Type[bool], Type[object]]]]]"; expected - # "Optional[Callable[[], Union[ExtensionDtype, str, dtype[Any], - # Type[object]]]]" - # error: Incompatible return value type (got "Union[ExtensionDtype, str, - # dtype[Any], Type[object], Dict[Hashable, Union[ExtensionDtype, Union[str, - # dtype[Any]], Type[str], Type[float], Type[int], Type[complex], Type[bool], - # Type[object]]]]", expected "Union[ExtensionDtype, str, dtype[Any], - # Type[object]]") - dtype = defaultdict( - lambda: default_dtype # type: ignore[arg-type, return-value] - ) + dtype_dict = defaultdict(lambda: default_dtype) else: dtype = cast(dict, dtype) - dtype = defaultdict( + dtype_dict = defaultdict( lambda: object, {columns[k] if is_integer(k) else k: v for k, v in dtype.items()}, ) @@ -1063,14 +1052,16 @@ def _get_empty_meta( if (index_col is None or index_col is False) or index_names is None: index = Index([]) else: - data = [Series([], dtype=dtype[name]) for name in index_names] + data = [Series([], dtype=dtype_dict[name]) for name in index_names] index = ensure_index_from_sequences(data, names=index_names) index_col.sort() for i, n in enumerate(index_col): columns.pop(n - i) - col_dict = {col_name: Series([], dtype=dtype[col_name]) for col_name in columns} + col_dict = { + col_name: Series([], dtype=dtype_dict[col_name]) for col_name in columns + } return index, columns, col_dict diff --git a/requirements-dev.txt b/requirements-dev.txt index a3f71ac2a3aa5..0f1d76b996df1 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.941 +mypy==0.950 pre-commit>=2.9.2 pycodestyle pyupgrade From eea8fa7cc54930017c1e8d83e1c6d75ba1791bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 2 May 2022 08:56:49 -0400 Subject: [PATCH 2/5] Update pandas/io/parsers/base_parser.py Co-authored-by: Simon Hawkins --- pandas/io/parsers/base_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 10fe6399bb81d..97ec297db8ba8 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -1028,7 +1028,7 @@ def _get_empty_meta( # Convert `dtype` to a defaultdict of some kind. # This will enable us to write `dtype[col_name]` # without worrying about KeyError issues later on. - dtype_dict: DefaultDict[Hashable, Any] + dtype_dict: defaultdict[Hashable, Any] if not is_dict_like(dtype): # if dtype == None, default will be object. default_dtype = dtype or object From b47075d432a12a1f4a0070c8e81e406112603cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 2 May 2022 19:11:46 -0400 Subject: [PATCH 3/5] use 'TypeVar-self' --- pandas/_libs/tslibs/timestamps.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 61deac3f3e1c5..4be9621a594dc 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -113,7 +113,7 @@ class Timestamp(datetime): def time(self) -> _time: ... def timetz(self) -> _time: ... def replace( - self, + self: _DatetimeT, year: int = ..., month: int = ..., day: int = ..., @@ -123,7 +123,7 @@ class Timestamp(datetime): microsecond: int = ..., tzinfo: _tzinfo | None = ..., fold: int = ..., - ) -> Timestamp: ... + ) -> _DatetimeT: ... def astimezone(self: _DatetimeT, tz: _tzinfo | None = ...) -> _DatetimeT: ... def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... From 8e3669f85acaa55fb097c085878c94d9aa09af5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 13 May 2022 19:17:11 -0400 Subject: [PATCH 4/5] fixed a reportInvalidTypeVarUse --- pandas/core/arrays/masked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index a7bb9520841b6..3616e3512c6fe 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -957,7 +957,7 @@ def equals(self, other) -> bool: return array_equivalent(left, right, dtype_equal=True) def _quantile( - self: BaseMaskedArrayT, qs: npt.NDArray[np.float64], interpolation: str + self, qs: npt.NDArray[np.float64], interpolation: str ) -> BaseMaskedArray: """ Dispatch to quantile_with_mask, needed because we do not have From 8f956667a9dc4993a8e97992f3c171bbd2c84f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 14 May 2022 17:01:28 -0400 Subject: [PATCH 5/5] yet another pyright release --- .github/workflows/code-checks.yml | 2 +- .pre-commit-config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index 6c3d34e5fabcd..7d24b26f5538b 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.246 + run: npm install -g pyright@1.1.247 - name: Build Pandas id: build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 41c94024b79f8..9469a34c8aacd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,7 +89,7 @@ repos: types: [python] stages: [manual] # note: keep version in sync with .github/workflows/code-checks.yml - additional_dependencies: ['pyright@1.1.246'] + additional_dependencies: ['pyright@1.1.247'] - repo: local hooks: - id: flake8-rst