Skip to content

CI: run stubtest #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Here are the most important options. Fore more details, please use `poe --help`.
- Run only pytest: `poe pytest`
- Run only pre-commit: `poe style`
- Run tests against the installed stubs (this will install and uninstall the stubs): `poe test_dist`
- Optional: Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list`

These tests originally came from https://github.com/VirtusLab/pandas-stubs.
Empty file.
10 changes: 5 additions & 5 deletions pandas-stubs/core/arrays/categorical.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class Categorical(ExtensionArray, PandasObject):
@overload
def set_ordered(self, value, inplace: Literal[True]) -> None: ...
@overload
def set_ordered(self, value, inplace: Literal[False]) -> Categorical: ...
def set_ordered(self, value, inplace: Literal[False] = ...) -> Categorical: ...
@overload
def set_ordered(self, value, inplace: bool) -> Categorical | None: ...
def set_ordered(self, value, inplace: bool = ...) -> Categorical | None: ...
@overload
def as_ordered(self, inplace: Literal[True]) -> None: ...
@overload
def as_ordered(self, inplace: Literal[False]) -> Categorical: ...
def as_ordered(self, inplace: Literal[False] = ...) -> Categorical: ...
@overload
def as_ordered(self, inplace: bool) -> Categorical | None: ...
def as_ordered(self, inplace: bool = ...) -> Categorical | None: ...
@overload
def as_unordered(self, inplace: Literal[True]) -> None: ...
@overload
Expand Down Expand Up @@ -155,7 +155,7 @@ class Categorical(ExtensionArray, PandasObject):
def __ge__(self, other) -> bool: ...
@property
def shape(self): ...
def shift(self, periods, fill_value=...): ...
def shift(self, periods=..., fill_value=...): ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ...
@property
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/computation/expressions.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def set_use_numexpr(v: bool = ...) -> None: ...
def set_numexpr_threads(n=...) -> None: ...
def evaluate(op, op_str, a, b, use_numexpr: bool = ...): ...
def evaluate(op, a, b, use_numexpr: bool = ...): ...
def where(cond, a, b, use_numexpr: bool = ...): ...
def set_test_mode(v: bool = ...) -> None: ...
def get_test_result(): ...
2 changes: 1 addition & 1 deletion pandas-stubs/core/computation/ops.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

class UndefinedVariableError(NameError):
def __init__(self, name, is_local: bool) -> None: ...
def __init__(self, name, is_local: bool = ...) -> None: ...

class Term:
def __new__(cls, name, env, side=..., encoding=...): ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ class DataFrame(NDFrame, OpsMixin):
fill_value: float | None = ...,
) -> DataFrame: ...
def droplevel(
self, level: Level | list[Level] = ..., axis: AxisType = ...
self, level: Level | list[Level], axis: AxisType = ...
) -> DataFrame: ...
def eq(
self, other, axis: AxisType = ..., level: Level | None = ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Index(IndexOpsMixin, PandasObject):
def map(self, mapper, na_action=...) -> Index: ...
def isin(self, values, level=...) -> np_ndarray_bool: ...
def slice_indexer(self, start=..., end=..., step=..., kind=...): ...
def get_slice_bound(self, label, side, kind): ...
def get_slice_bound(self, label, side, kind=...): ...
def slice_locs(self, start=..., end=..., step=..., kind=...): ...
def delete(self, loc): ...
def insert(self, loc, item): ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/category.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CategoricalIndex(ExtensionIndex, accessor.PandasDelegate):
def __contains__(self, key) -> bool: ...
def __array__(self, dtype=...) -> np.ndarray: ...
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Index: ...
def fillna(self, value, downcast=...): ...
def fillna(self, value=..., downcast=...): ...
def is_unique(self) -> bool: ...
@property
def is_monotonic_increasing(self) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class MultiIndex(Index):
def get_indexer_non_unique(self, target): ...
def reindex(self, target, method=..., level=..., limit=..., tolerance=...): ...
def get_slice_bound(
self, label: Hashable | Sequence[Hashable], side: str, kind: str
self, label: Hashable | Sequence[Hashable], side: str, kind: str = ...
) -> int: ...
def slice_locs(self, start=..., end=..., step=..., kind=...): ...
def get_loc(self, key, method=...): ...
Expand Down
12 changes: 0 additions & 12 deletions pandas-stubs/core/ops/roperator.pyi

This file was deleted.

6 changes: 2 additions & 4 deletions pandas-stubs/core/resample.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ from pandas.core.groupby.grouper import Grouper as Grouper
from pandas._typing import FrameOrSeriesUnion

class Resampler(BaseGroupBy, ShallowMixin):
def __init__(
self, obj, groupby=..., axis: int = ..., kind=..., **kwargs
) -> None: ...
def __init__(self, obj, groupby, axis: int = ..., kind=..., **kwargs) -> None: ...
def __getattr__(self, attr: str): ...
def __iter__(self): ...
@property
def obj(self): ...
@property
def ax(self): ...
def pipe(self, func, *args, **kwargs): ...
def aggregate(self, func, *args, **kwargs): ...
def aggregate(self, func=..., *args, **kwargs): ...
agg = aggregate
def transform(self, arg, *args, **kwargs): ...
def pad(self, limit=...): ...
Expand Down
27 changes: 0 additions & 27 deletions pandas-stubs/core/reshape/reshape.pyi
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import numpy as np
from pandas.core.frame import DataFrame

class _Unstacker:
values = ...
value_columns = ...
fill_value = ...
constructor = ...
index = ...
level = ...
lift = ...
new_index_levels = ...
new_index_names = ...
removed_name = ...
removed_level = ...
removed_level_full = ...
def __init__(
self,
values: np.ndarray,
index,
level=...,
value_columns=...,
fill_value=...,
constructor=...,
) -> None: ...
def get_result(self): ...
def get_new_values(self): ...
def get_new_columns(self): ...
def get_new_index(self): ...

def unstack(obj, level, fill_value=...): ...
def stack(frame, level: int = ..., dropna: bool = ...): ...
def stack_multiple(frame, level, dropna: bool = ...): ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
def count(self, level: None = ...) -> int: ...
@overload
def count(self, level: Hashable) -> Series[S1]: ...
def mode(self, dropna) -> Series[S1]: ...
def mode(self, dropna=...) -> Series[S1]: ...
def unique(self) -> np.ndarray: ...
@overload
def drop_duplicates(
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/window/rolling.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _Window(PandasObject, ShallowMixin, SelectionMixin):
def __getattr__(self, attr: str): ...
def __iter__(self): ...
def aggregate(
self, func: Callable | None = ..., *args, **kwargs
self, func: Callable | None, *args, **kwargs
) -> Scalar | FrameOrSeries: ...
agg = aggregate

Expand Down
7 changes: 0 additions & 7 deletions pandas-stubs/io/gcs.pyi

This file was deleted.

2 changes: 1 addition & 1 deletion pandas-stubs/io/parquet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FastParquetImpl(BaseImpl):

def to_parquet(
df: DataFrame,
path,
path=...,
engine: str = ...,
compression=...,
index: bool | None = ...,
Expand Down
18 changes: 0 additions & 18 deletions pandas-stubs/io/s3.pyi

This file was deleted.

3 changes: 1 addition & 2 deletions pandas-stubs/io/sql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from typing import (
from pandas.core.base import PandasObject
from pandas.core.frame import DataFrame

class SQLAlchemyRequired(ImportError): ...
class DatabaseError(IOError): ...

def execute(sql, con, cur=..., params=...): ...
Expand All @@ -33,7 +32,7 @@ def read_sql_query(
) -> DataFrame: ...
def read_sql(
sql: str | Any,
con: str | Any = ...,
con: str | Any,
index_col: str | Sequence[str] | None = ...,
coerce_float: bool = ...,
params: Sequence[str] | tuple[str, ...] | Mapping[str, str] | None = ...,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/util/_print_versions.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
def get_sys_info() -> list[tuple[str, str | int | None]]: ...
def show_versions(as_json: bool = ...) -> None: ...
def main() -> int: ...
5 changes: 0 additions & 5 deletions pandas-stubs/util/_test_decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
from typing import Callable

def safe_import(mod_name: str, min_version: str | None = ...): ...

tables = ...
xfail_non_writeable = ...

def skip_if_installed(package: str) -> Callable: ...
def skip_if_no(package: str, min_version: str | None = ...) -> Callable: ...

skip_if_no_mpl = ...
skip_if_mpl = ...
skip_if_32bit = ...
skip_if_windows = ...
skip_if_windows_python_3 = ...
skip_if_has_locale = ...
skip_if_not_us_locale = ...
skip_if_no_scipy = ...
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ script = "scripts.test.run:pyright_src"
help = "Run pyright on 'tests' using the installed stubs"
script = "scripts.test:test(dist=True, type_checker='pyright')"

[tool.poe.tasks.stubtest]
script = "scripts.test:stubtest(allowlist)"
help = "Run stubtest to compare the installed stubs against pandas"
args = [{ name = "allowlist", positional = true, default = "", required = false, help= "Path to an allowlist (optional)" }]


[tool.black]
Expand Down
3 changes: 3 additions & 0 deletions scripts/_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ def run_job(steps: List[Step]) -> None:
end = time.perf_counter()
logger.success(f"End: '{step.name}', runtime: {end - start:.3f} seconds.")

if not failed:
__rollback_job(rollback_steps)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated: run the rollbacks when none of the steps failed (instead of having to specify the rollback as a step)


if failed:
sys.exit(1)
11 changes: 9 additions & 2 deletions scripts/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dataclasses
from functools import partial
from typing import Literal

from scripts._job import run_job
Expand All @@ -10,8 +12,6 @@
_step.rename_src,
_step.mypy_dist,
_step.pyright_dist,
_step.uninstall_dist,
_step.restore_src,
]


Expand All @@ -33,3 +33,10 @@ def test(
steps = [step for step in steps if remove not in step.name]

run_job(steps)


def stubtest(allowlist: str):
stubtest = dataclasses.replace(
_step.stubtest, run=partial(_step.stubtest.run, allowlist=allowlist)
)
run_job(_DIST_STEPS[:-2] + [stubtest])
5 changes: 3 additions & 2 deletions scripts/test/_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
pyright_dist = Step(
name="Run pyright on 'tests' using the installed stubs", run=run.pyright_dist
)
uninstall_dist = Step(name="Uninstall pandas-stubs", run=run.uninstall_dist)
restore_src = Step(name="Restore local stubs", run=run.restore_src)
stubtest = Step(
name="Run stubtest to compare the installed stubs against pandas", run=run.stubtest
)
17 changes: 17 additions & 0 deletions scripts/test/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import subprocess
import sys


def mypy_src():
Expand All @@ -22,6 +23,22 @@ def style():
subprocess.run(cmd, check=True)


def stubtest(allowlist: str = ""):
cmd = [
sys.executable,
"-m",
"mypy.stubtest",
"pandas",
"--concise",
"--ignore-missing-stub",
"--mypy-config-file",
"pyproject.toml",
]
if allowlist:
cmd += ["--allowlist", allowlist]
subprocess.run(cmd, check=True)


def build_dist():
cmd = ["poetry", "build", "-f", "wheel"]
subprocess.run(cmd, check=True)
Expand Down