From 802bd12685f4935c70fb8c598077695cc40829d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 4 Sep 2022 11:32:19 -0400 Subject: [PATCH 1/4] Hide pandas implementation during type checking --- pandas-stubs/core/dtypes/generic.pyi | 15 +++++++++++++++ pandas-stubs/core/groupby/groupby.pyi | 3 +-- pandas-stubs/util/__init__.pyi | 7 ------- pyproject.toml | 8 +++----- scripts/test/__init__.py | 15 ++++++++++++--- scripts/test/_step.py | 1 + scripts/test/run.py | 12 ++++++++++++ 7 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 pandas-stubs/core/dtypes/generic.pyi diff --git a/pandas-stubs/core/dtypes/generic.pyi b/pandas-stubs/core/dtypes/generic.pyi new file mode 100644 index 000000000..380d600f5 --- /dev/null +++ b/pandas-stubs/core/dtypes/generic.pyi @@ -0,0 +1,15 @@ +from pandas import ( + DataFrame, + Index, + Series, +) +from pandas.core.arrays import ExtensionArray +from pandas.core.generic import NDFrame + +ABCIndex = type[Index] + +ABCNDFrame = type[NDFrame] +ABCSeries = type[Series] +ABCDataFrame = type[DataFrame] + +ABCExtensionArray = type[ExtensionArray] diff --git a/pandas-stubs/core/groupby/groupby.pyi b/pandas-stubs/core/groupby/groupby.pyi index d772b795c..538a44fd8 100644 --- a/pandas-stubs/core/groupby/groupby.pyi +++ b/pandas-stubs/core/groupby/groupby.pyi @@ -7,7 +7,6 @@ from pandas.core.base import ( from pandas.core.frame import DataFrame from pandas.core.generic import NDFrame from pandas.core.groupby import ops -from pandas.core.groupby.indexing import GroupByIndexingMixin from pandas.core.indexes.api import Index from pandas.core.series import Series @@ -23,7 +22,7 @@ class GroupByPlot(PandasObject): def __call__(self, *args, **kwargs): ... def __getattr__(self, name: str): ... -class BaseGroupBy(PandasObject, SelectionMixin[NDFrameT], GroupByIndexingMixin): +class BaseGroupBy(PandasObject, SelectionMixin[NDFrameT]): level = ... as_index = ... keys = ... diff --git a/pandas-stubs/util/__init__.pyi b/pandas-stubs/util/__init__.pyi index 137c9a73c..cd7193530 100644 --- a/pandas-stubs/util/__init__.pyi +++ b/pandas-stubs/util/__init__.pyi @@ -8,10 +8,3 @@ from ._decorators import ( Substitution as Substitution, cache_readonly as cache_readonly, ) - -def __getattr__(name): ... - -class _testing: - def __getattr__(self, item): ... - -testing = ... diff --git a/pyproject.toml b/pyproject.toml index e0adeb4a2..322ca298a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ script = "scripts.test.run:style" [tool.poe.tasks.mypy] help = "Run mypy on 'tests' (using the local stubs) and on the local stubs" -script = "scripts.test.run:mypy_src" +script = "scripts.test:test(src=True, type_checker='mypy')" [tool.poe.tasks.mypy_dist] help = "Run mypy on 'tests' using the installed stubs" @@ -90,7 +90,7 @@ script = "scripts.test:test(dist=True, type_checker='mypy')" [tool.poe.tasks.pyright] help = "Run pyright on 'tests' (using the local stubs) and on the local stubs" -script = "scripts.test.run:pyright_src" +script = "scripts.test:test(src=True, type_checker='pyright')" [tool.poe.tasks.pyright_dist] help = "Run pyright on 'tests' using the installed stubs" @@ -170,8 +170,8 @@ typeCheckingMode = "strict" stubPath = "." include = ["tests", "pandas-stubs"] # disable subset of strict -reportIncompleteStub = false reportInconsistentConstructor = false +reportMissingModuleSource = false reportMissingParameterType = false reportMissingTypeArgument = false reportMissingTypeStubs = false @@ -184,5 +184,3 @@ reportUnknownVariableType = false reportUntypedBaseClass = false reportUnusedVariable = false reportPrivateUsage = false -# enable optional checks -reportMissingModuleSource = true diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index 02d053947..f087d4b65 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -5,7 +5,13 @@ from scripts._job import run_job from scripts.test import _step -_SRC_STEPS = [_step.mypy_src, _step.pyright_src, _step.pytest, _step.style] +_SRC_STEPS = [ + _step.pytest, + _step.style, + _step.rename_pandas, + _step.mypy_src, + _step.pyright_src, +] _DIST_STEPS = [ _step.build_dist, _step.install_dist, @@ -29,8 +35,11 @@ def test( if type_checker: # either pyright or mypy - remove = "mypy" if type_checker == "pyright" else "pyright" - steps = [step for step in steps if remove not in step.name] + removes = ["mypy" if type_checker == "pyright" else "pyright"] + removes.extend(["pytest", "pre-commit"]) + steps = [ + step for step in steps if all(remove not in step.name for remove in removes) + ] run_job(steps) diff --git a/scripts/test/_step.py b/scripts/test/_step.py index 56b4d4a02..238d35d62 100644 --- a/scripts/test/_step.py +++ b/scripts/test/_step.py @@ -20,6 +20,7 @@ run=run.rename_src, rollback=run.restore_src, ) +rename_pandas = Step(name="Rename pandas implementation", **run.get_pandas_renamer()) mypy_dist = Step( name="Run mypy on 'tests' using the installed stubs", run=run.mypy_dist ) diff --git a/scripts/test/run.py b/scripts/test/run.py index 145e4b2b2..810820664 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -1,6 +1,8 @@ +from functools import partial from pathlib import Path import subprocess import sys +from typing import Callable def mypy_src(): @@ -105,3 +107,13 @@ def released_pandas(): cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"] subprocess.run(cmd, check=True) + + +def get_pandas_renamer() -> dict[str, Callable[[], None]]: + cmd = [sys.executable, "-c", "import pandas; print(pandas.__path__[0])"] + path = Path(subprocess.check_output(cmd).decode().strip()) + hidden = path.parent / f"_{path.name}" + return { + "run": partial(path.rename, hidden), + "rollback": partial(hidden.rename, path), + } From 04d40b7e1e324712bc3992c46af9969518318274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 4 Sep 2022 11:40:41 -0400 Subject: [PATCH 2/4] 3.8 --- scripts/test/run.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test/run.py b/scripts/test/run.py index 810820664..6d821c018 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from functools import partial from pathlib import Path import subprocess From 64b7a05e04f21f44a10bf3540729ce4ad09ef4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 4 Sep 2022 18:11:02 -0400 Subject: [PATCH 3/4] use py.typed --- pandas-stubs/py.typed | 0 pyproject.toml | 8 +++++--- scripts/test/__init__.py | 15 +++------------ scripts/test/_step.py | 1 - scripts/test/run.py | 14 -------------- 5 files changed, 8 insertions(+), 30 deletions(-) create mode 100644 pandas-stubs/py.typed diff --git a/pandas-stubs/py.typed b/pandas-stubs/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/pyproject.toml b/pyproject.toml index 322ca298a..e0adeb4a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ script = "scripts.test.run:style" [tool.poe.tasks.mypy] help = "Run mypy on 'tests' (using the local stubs) and on the local stubs" -script = "scripts.test:test(src=True, type_checker='mypy')" +script = "scripts.test.run:mypy_src" [tool.poe.tasks.mypy_dist] help = "Run mypy on 'tests' using the installed stubs" @@ -90,7 +90,7 @@ script = "scripts.test:test(dist=True, type_checker='mypy')" [tool.poe.tasks.pyright] help = "Run pyright on 'tests' (using the local stubs) and on the local stubs" -script = "scripts.test:test(src=True, type_checker='pyright')" +script = "scripts.test.run:pyright_src" [tool.poe.tasks.pyright_dist] help = "Run pyright on 'tests' using the installed stubs" @@ -170,8 +170,8 @@ typeCheckingMode = "strict" stubPath = "." include = ["tests", "pandas-stubs"] # disable subset of strict +reportIncompleteStub = false reportInconsistentConstructor = false -reportMissingModuleSource = false reportMissingParameterType = false reportMissingTypeArgument = false reportMissingTypeStubs = false @@ -184,3 +184,5 @@ reportUnknownVariableType = false reportUntypedBaseClass = false reportUnusedVariable = false reportPrivateUsage = false +# enable optional checks +reportMissingModuleSource = true diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index f087d4b65..02d053947 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -5,13 +5,7 @@ from scripts._job import run_job from scripts.test import _step -_SRC_STEPS = [ - _step.pytest, - _step.style, - _step.rename_pandas, - _step.mypy_src, - _step.pyright_src, -] +_SRC_STEPS = [_step.mypy_src, _step.pyright_src, _step.pytest, _step.style] _DIST_STEPS = [ _step.build_dist, _step.install_dist, @@ -35,11 +29,8 @@ def test( if type_checker: # either pyright or mypy - removes = ["mypy" if type_checker == "pyright" else "pyright"] - removes.extend(["pytest", "pre-commit"]) - steps = [ - step for step in steps if all(remove not in step.name for remove in removes) - ] + remove = "mypy" if type_checker == "pyright" else "pyright" + steps = [step for step in steps if remove not in step.name] run_job(steps) diff --git a/scripts/test/_step.py b/scripts/test/_step.py index 238d35d62..56b4d4a02 100644 --- a/scripts/test/_step.py +++ b/scripts/test/_step.py @@ -20,7 +20,6 @@ run=run.rename_src, rollback=run.restore_src, ) -rename_pandas = Step(name="Rename pandas implementation", **run.get_pandas_renamer()) mypy_dist = Step( name="Run mypy on 'tests' using the installed stubs", run=run.mypy_dist ) diff --git a/scripts/test/run.py b/scripts/test/run.py index 6d821c018..145e4b2b2 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -1,10 +1,6 @@ -from __future__ import annotations - -from functools import partial from pathlib import Path import subprocess import sys -from typing import Callable def mypy_src(): @@ -109,13 +105,3 @@ def released_pandas(): cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"] subprocess.run(cmd, check=True) - - -def get_pandas_renamer() -> dict[str, Callable[[], None]]: - cmd = [sys.executable, "-c", "import pandas; print(pandas.__path__[0])"] - path = Path(subprocess.check_output(cmd).decode().strip()) - hidden = path.parent / f"_{path.name}" - return { - "run": partial(path.rename, hidden), - "rollback": partial(hidden.rename, path), - } From d14d444a1caedb9698195393d4b5a0c430da8db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 4 Sep 2022 18:16:04 -0400 Subject: [PATCH 4/4] enable reportIncompleteStub --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e0adeb4a2..313700414 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -170,7 +170,6 @@ typeCheckingMode = "strict" stubPath = "." include = ["tests", "pandas-stubs"] # disable subset of strict -reportIncompleteStub = false reportInconsistentConstructor = false reportMissingParameterType = false reportMissingTypeArgument = false