From 7bd63994ed5df4c043c62efef7b4912414a60e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 4 Jun 2022 22:52:32 -0400 Subject: [PATCH 1/8] CI/TYP: enable reportGeneralTypeIssues for subset of files --- .pre-commit-config.yaml | 13 ++- pandas/util/_doctools.py | 4 +- pyright_reportGeneralTypeIssues.json | 129 +++++++++++++++++++++++++++ typings/numba.pyi | 4 +- 4 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 pyright_reportGeneralTypeIssues.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 266e5a015e408..635c749d88c1e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -93,7 +93,18 @@ repos: pass_filenames: false types: [python] stages: [manual] - additional_dependencies: ['pyright@1.1.248'] + additional_dependencies: ['pyright@1.1.252'] +- repo: local + hooks: + - id: pyright_reportGeneralTypeIssues + name: pyright reportGeneralTypeIssues + entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json + # note: assumes python env is setup and activated + language: node + pass_filenames: false + types: [python] + stages: [manual] + additional_dependencies: ['pyright@1.1.252'] - repo: local hooks: - id: mypy diff --git a/pandas/util/_doctools.py b/pandas/util/_doctools.py index 18fb9a7e055b5..7353bef370000 100644 --- a/pandas/util/_doctools.py +++ b/pandas/util/_doctools.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import Sequence + import numpy as np import pandas as pd @@ -41,7 +43,7 @@ def _get_cells(self, left, right, vertical) -> tuple[int, int]: hcells = sum([self._shape(df)[1] for df in left] + [self._shape(right)[1]]) return hcells, vcells - def plot(self, left, right, labels=None, vertical: bool = True): + def plot(self, left, right, labels: Sequence[str] = (), vertical: bool = True): """ Plot left / right DataFrames in specified layout. diff --git a/pyright_reportGeneralTypeIssues.json b/pyright_reportGeneralTypeIssues.json new file mode 100644 index 0000000000000..0940c570909bd --- /dev/null +++ b/pyright_reportGeneralTypeIssues.json @@ -0,0 +1,129 @@ +# this becomes obsolet when reportGeneralTypeIssues can be enabled in pyproject.toml +{ + "typeCheckingMode": "off", + "reportGeneralTypeIssues": true, + "include": + [ + "pandas", + "typings" + ], + "exclude": + [ + # exclude tests + "pandas/tests", + # and all files that currently don't pass + "pandas/_config/config.py", + "pandas/core/algorithms.py", + "pandas/core/apply.py", + "pandas/core/array_algos/take.py", + "pandas/core/arrays/_mixins.py", + "pandas/core/arrays/_ranges.py", + "pandas/core/arrays/arrow/_arrow_utils.py", + "pandas/core/arrays/arrow/array.py", + "pandas/core/arrays/base.py", + "pandas/core/arrays/boolean.py", + "pandas/core/arrays/categorical.py", + "pandas/core/arrays/datetimelike.py", + "pandas/core/arrays/datetimes.py", + "pandas/core/arrays/interval.py", + "pandas/core/arrays/masked.py", + "pandas/core/arrays/numeric.py", + "pandas/core/arrays/period.py", + "pandas/core/arrays/sparse/array.py", + "pandas/core/arrays/sparse/dtype.py", + "pandas/core/arrays/string_.py", + "pandas/core/arrays/string_arrow.py", + "pandas/core/arrays/timedeltas.py", + "pandas/core/common.py", + "pandas/core/computation/align.py", + "pandas/core/construction.py", + "pandas/core/describe.py", + "pandas/core/dtypes/base.py", + "pandas/core/dtypes/cast.py", + "pandas/core/dtypes/common.py", + "pandas/core/dtypes/concat.py", + "pandas/core/dtypes/dtypes.py", + "pandas/core/frame.py", + "pandas/core/generic.py", + "pandas/core/groupby/generic.py", + "pandas/core/groupby/groupby.py", + "pandas/core/groupby/grouper.py", + "pandas/core/groupby/ops.py", + "pandas/core/indexers/objects.py", + "pandas/core/indexers/utils.py", + "pandas/core/indexes/base.py", + "pandas/core/indexes/category.py", + "pandas/core/indexes/datetimelike.py", + "pandas/core/indexes/datetimes.py", + "pandas/core/indexes/extension.py", + "pandas/core/indexes/interval.py", + "pandas/core/indexes/multi.py", + "pandas/core/indexes/numeric.py", + "pandas/core/indexes/period.py", + "pandas/core/indexes/range.py", + "pandas/core/indexing.py", + "pandas/core/internals/api.py", + "pandas/core/internals/array_manager.py", + "pandas/core/internals/base.py", + "pandas/core/internals/blocks.py", + "pandas/core/internals/concat.py", + "pandas/core/internals/construction.py", + "pandas/core/internals/managers.py", + "pandas/core/missing.py", + "pandas/core/nanops.py", + "pandas/core/resample.py", + "pandas/core/reshape/concat.py", + "pandas/core/reshape/merge.py", + "pandas/core/reshape/pivot.py", + "pandas/core/reshape/reshape.py", + "pandas/core/reshape/tile.py", + "pandas/core/series.py", + "pandas/core/sorting.py", + "pandas/core/strings/accessor.py", + "pandas/core/tools/datetimes.py", + "pandas/core/tools/timedeltas.py", + "pandas/core/util/hashing.py", + "pandas/core/util/numba_.py", + "pandas/core/window/ewm.py", + "pandas/core/window/expanding.py", + "pandas/core/window/rolling.py", + "pandas/io/common.py", + "pandas/io/excel/_base.py", + "pandas/io/excel/_odfreader.py", + "pandas/io/excel/_odswriter.py", + "pandas/io/excel/_openpyxl.py", + "pandas/io/excel/_pyxlsb.py", + "pandas/io/excel/_xlrd.py", + "pandas/io/formats/csvs.py", + "pandas/io/formats/excel.py", + "pandas/io/formats/format.py", + "pandas/io/formats/html.py", + "pandas/io/formats/info.py", + "pandas/io/formats/printing.py", + "pandas/io/formats/style.py", + "pandas/io/formats/style_render.py", + "pandas/io/formats/xml.py", + "pandas/io/json/_json.py", + "pandas/io/parquet.py", + "pandas/io/parsers/arrow_parser_wrapper.py", + "pandas/io/parsers/base_parser.py", + "pandas/io/parsers/c_parser_wrapper.py", + "pandas/io/parsers/python_parser.py", + "pandas/io/parsers/readers.py", + "pandas/io/pytables.py", + "pandas/io/sas/sas7bdat.py", + "pandas/io/sas/sasreader.py", + "pandas/io/sql.py", + "pandas/io/stata.py", + "pandas/io/xml.py", + "pandas/plotting/_core.py", + "pandas/plotting/_matplotlib/converter.py", + "pandas/plotting/_matplotlib/core.py", + "pandas/plotting/_matplotlib/hist.py", + "pandas/plotting/_matplotlib/misc.py", + "pandas/plotting/_matplotlib/style.py", + "pandas/plotting/_matplotlib/timeseries.py", + "pandas/plotting/_matplotlib/tools.py", + "pandas/tseries/frequencies.py", + ], +} diff --git a/typings/numba.pyi b/typings/numba.pyi index f877cbf339a8b..36cccb894049b 100644 --- a/typings/numba.pyi +++ b/typings/numba.pyi @@ -12,9 +12,7 @@ from pandas._typing import F def __getattr__(name: str) -> Any: ... # incomplete @overload -def jit( - signature_or_function: F = ..., -) -> F: ... +def jit(signature_or_function: F) -> F: ... @overload def jit( signature_or_function: str From c9252798ee58cd9f6a4e105e6bb8c2d9f551023a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 6 Jun 2022 10:13:31 -0400 Subject: [PATCH 2/8] labels can be Iterable[str] --- pandas/util/_doctools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/util/_doctools.py b/pandas/util/_doctools.py index 7353bef370000..cb4ceb052a8e0 100644 --- a/pandas/util/_doctools.py +++ b/pandas/util/_doctools.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Sequence +from typing import Iterable import numpy as np @@ -43,7 +43,7 @@ def _get_cells(self, left, right, vertical) -> tuple[int, int]: hcells = sum([self._shape(df)[1] for df in left] + [self._shape(right)[1]]) return hcells, vcells - def plot(self, left, right, labels: Sequence[str] = (), vertical: bool = True): + def plot(self, left, right, labels: Iterable[str] = (), vertical: bool = True): """ Plot left / right DataFrames in specified layout. From 0677b62f4ba305c4ac964774426b57df18a5d9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 6 Jun 2022 12:41:23 -0400 Subject: [PATCH 3/8] fix no_default --- pandas/_libs/lib.pyi | 3 ++- pyright_reportGeneralTypeIssues.json | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index d4a766f7086af..02f021128cbed 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -4,6 +4,7 @@ from typing import ( Any, Callable, + Final, Generator, Hashable, Literal, @@ -26,7 +27,7 @@ from enum import Enum class _NoDefault(Enum): no_default = ... -no_default = _NoDefault.no_default +no_default: Final = _NoDefault.no_default NoDefault = Literal[_NoDefault.no_default] i8max: int diff --git a/pyright_reportGeneralTypeIssues.json b/pyright_reportGeneralTypeIssues.json index 0940c570909bd..a4e74a850f4fb 100644 --- a/pyright_reportGeneralTypeIssues.json +++ b/pyright_reportGeneralTypeIssues.json @@ -18,7 +18,6 @@ "pandas/core/array_algos/take.py", "pandas/core/arrays/_mixins.py", "pandas/core/arrays/_ranges.py", - "pandas/core/arrays/arrow/_arrow_utils.py", "pandas/core/arrays/arrow/array.py", "pandas/core/arrays/base.py", "pandas/core/arrays/boolean.py", @@ -97,7 +96,6 @@ "pandas/io/formats/csvs.py", "pandas/io/formats/excel.py", "pandas/io/formats/format.py", - "pandas/io/formats/html.py", "pandas/io/formats/info.py", "pandas/io/formats/printing.py", "pandas/io/formats/style.py", From 27e8f80986b9a3e22a3fe4c8515dcceb544d4fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 6 Jun 2022 17:11:05 -0400 Subject: [PATCH 4/8] specify pyright version only once --- .pre-commit-config.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 635c749d88c1e..7dc53ab6f3e7b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -93,18 +93,19 @@ repos: pass_filenames: false types: [python] stages: [manual] - additional_dependencies: ['pyright@1.1.252'] + additional_dependencies: &pyright_dependencies + - pyright@1.1.252 - repo: local hooks: - id: pyright_reportGeneralTypeIssues name: pyright reportGeneralTypeIssues - entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json + entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json # note: assumes python env is setup and activated language: node pass_filenames: false types: [python] stages: [manual] - additional_dependencies: ['pyright@1.1.252'] + additional_dependencies: *pyright_dependencies - repo: local hooks: - id: mypy From 0aba5d096e4c01d7ca4e7a89b51b47e668681d3f Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Mon, 6 Jun 2022 05:38:24 -0400 Subject: [PATCH 5/8] TYP: remove mypy ignore from localization.py (#47240) * TYP: remove mypy ignore from localization.py * fixup! TYP: remove mypy ignore from localization.py --- pandas/_config/localization.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/_config/localization.py b/pandas/_config/localization.py index 2e1ef31033d71..fa5503029fd4b 100644 --- a/pandas/_config/localization.py +++ b/pandas/_config/localization.py @@ -43,11 +43,9 @@ def set_locale( try: locale.setlocale(lc_var, new_locale) - normalized_locale = locale.getlocale() - if all(x is not None for x in 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] + normalized_code, normalized_encoding = locale.getlocale() + if normalized_code is not None and normalized_encoding is not None: + yield f"{normalized_code}.{normalized_encoding}" else: yield new_locale finally: From a596b6bc9eb53b5b4ed53e985ce88eaa6919ad8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 6 Jun 2022 17:11:05 -0400 Subject: [PATCH 6/8] specify pyright version only once --- .pre-commit-config.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 635c749d88c1e..7dc53ab6f3e7b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -93,18 +93,19 @@ repos: pass_filenames: false types: [python] stages: [manual] - additional_dependencies: ['pyright@1.1.252'] + additional_dependencies: &pyright_dependencies + - pyright@1.1.252 - repo: local hooks: - id: pyright_reportGeneralTypeIssues name: pyright reportGeneralTypeIssues - entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json + entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json # note: assumes python env is setup and activated language: node pass_filenames: false types: [python] stages: [manual] - additional_dependencies: ['pyright@1.1.252'] + additional_dependencies: *pyright_dependencies - repo: local hooks: - id: mypy From cfdd75e223fcb17151a1cca8e4bc627dd0402869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Wed, 8 Jun 2022 08:55:26 -0400 Subject: [PATCH 7/8] bump pyright --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7dc53ab6f3e7b..25fafb7800bb4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -94,7 +94,7 @@ repos: types: [python] stages: [manual] additional_dependencies: &pyright_dependencies - - pyright@1.1.252 + - pyright@1.1.253 - repo: local hooks: - id: pyright_reportGeneralTypeIssues From 1055b2f10d3ce1ebd9fcb1642cdfe13252da3d6b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Wed, 8 Jun 2022 09:45:49 -0700 Subject: [PATCH 8/8] Update pyright_reportGeneralTypeIssues.json --- pyright_reportGeneralTypeIssues.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyright_reportGeneralTypeIssues.json b/pyright_reportGeneralTypeIssues.json index a4e74a850f4fb..22d607eb958e1 100644 --- a/pyright_reportGeneralTypeIssues.json +++ b/pyright_reportGeneralTypeIssues.json @@ -1,4 +1,4 @@ -# this becomes obsolet when reportGeneralTypeIssues can be enabled in pyproject.toml +# this becomes obsolete when reportGeneralTypeIssues can be enabled in pyproject.toml { "typeCheckingMode": "off", "reportGeneralTypeIssues": true,