diff --git a/pandas-stubs/_testing/__init__.pyi b/pandas-stubs/_testing/__init__.pyi index e07f6089a..a8aae1527 100644 --- a/pandas-stubs/_testing/__init__.pyi +++ b/pandas-stubs/_testing/__init__.pyi @@ -176,7 +176,7 @@ def assert_frame_equal( def assert_equal(left, right, **kwargs: Any) -> None: ... def assert_sp_array_equal(left: SparseArray, right: SparseArray) -> None: ... def assert_contains_all(iterable: Iterable[T], dic: Container[T]) -> None: ... -def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs) -> None: ... +def assert_copy(iter1: Iterable[T], iter2: Iterable[T], **eql_kwargs: Any) -> None: ... @contextmanager def assert_produces_warning( expected_warning: ( diff --git a/pandas-stubs/core/arrays/base.pyi b/pandas-stubs/core/arrays/base.pyi index d09ee0f4a..9f95ab8e1 100644 --- a/pandas-stubs/core/arrays/base.pyi +++ b/pandas-stubs/core/arrays/base.pyi @@ -21,6 +21,8 @@ from pandas._typing import ( from pandas.core.dtypes.dtypes import ExtensionDtype as ExtensionDtype class ExtensionArray: + def __array__(self, dtype=...) -> np_1darray: ... + def __array_ufunc__(self, ufunc, method, *inputs: Any, **kwargs: Any): ... @overload def __getitem__(self, item: ScalarIndexer) -> Any: ... @overload diff --git a/pandas-stubs/core/arrays/boolean.pyi b/pandas-stubs/core/arrays/boolean.pyi index e116d032d..fb9f897d7 100644 --- a/pandas-stubs/core/arrays/boolean.pyi +++ b/pandas-stubs/core/arrays/boolean.pyi @@ -20,7 +20,6 @@ class BooleanArray(BaseMaskedArray): ) -> None: ... @property def dtype(self): ... - def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ... def __setitem__(self, key, value) -> None: ... def astype(self, dtype, copy: bool = True): ... def any(self, *, skipna: bool = ..., **kwargs: Any): ... diff --git a/pandas-stubs/core/arrays/categorical.pyi b/pandas-stubs/core/arrays/categorical.pyi index 0992f1a56..cbadf74cc 100644 --- a/pandas-stubs/core/arrays/categorical.pyi +++ b/pandas-stubs/core/arrays/categorical.pyi @@ -89,8 +89,6 @@ class Categorical(ExtensionArray): @property def shape(self): ... def shift(self, periods=1, fill_value=...): ... - def __array__(self, dtype=...) -> np_1darray: ... - def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ... @property def T(self): ... @property @@ -112,7 +110,6 @@ class Categorical(ExtensionArray): def take( self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=... ) -> Categorical: ... - def __len__(self) -> int: ... def __iter__(self): ... def __contains__(self, key) -> bool: ... @overload diff --git a/pandas-stubs/core/arrays/datetimelike.pyi b/pandas-stubs/core/arrays/datetimelike.pyi index 74f62e405..71c047320 100644 --- a/pandas-stubs/core/arrays/datetimelike.pyi +++ b/pandas-stubs/core/arrays/datetimelike.pyi @@ -66,10 +66,8 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray): def asi8(self) -> np.ndarray: ... @property def nbytes(self): ... - def __array__(self, dtype=...) -> np.ndarray: ... @property def size(self) -> int: ... - def __len__(self) -> int: ... @overload def __getitem__(self, key: ScalarIndexer) -> DTScalarOrNaT: ... @overload diff --git a/pandas-stubs/core/arrays/datetimes.pyi b/pandas-stubs/core/arrays/datetimes.pyi index bb82f68cf..02c6e55d6 100644 --- a/pandas-stubs/core/arrays/datetimes.pyi +++ b/pandas-stubs/core/arrays/datetimes.pyi @@ -29,7 +29,6 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps): def tzinfo(self) -> _tzinfo | None: ... @property def is_normalized(self): ... - def __array__(self, dtype=...) -> np.ndarray: ... def __iter__(self): ... def astype(self, dtype, copy: bool = True): ... def tz_convert(self, tz: TimeZones): ... diff --git a/pandas-stubs/core/arrays/integer.pyi b/pandas-stubs/core/arrays/integer.pyi index a83268c83..0401c1925 100644 --- a/pandas-stubs/core/arrays/integer.pyi +++ b/pandas-stubs/core/arrays/integer.pyi @@ -1,5 +1,3 @@ -from typing import Any - from pandas.core.arrays.masked import BaseMaskedArray from pandas._libs.missing import NAType @@ -19,7 +17,6 @@ class IntegerArray(BaseMaskedArray): @property def dtype(self) -> _IntegerDtype: ... def __init__(self, values, mask, copy: bool = ...) -> None: ... - def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ... def __setitem__(self, key, value) -> None: ... def astype(self, dtype, copy: bool = True): ... diff --git a/pandas-stubs/core/arrays/interval.pyi b/pandas-stubs/core/arrays/interval.pyi index ad97dd547..6409d7cda 100644 --- a/pandas-stubs/core/arrays/interval.pyi +++ b/pandas-stubs/core/arrays/interval.pyi @@ -58,7 +58,6 @@ class IntervalArray(IntervalMixin, ExtensionArray): dtype=None, ): ... def __iter__(self): ... - def __len__(self) -> int: ... @overload def __getitem__(self, key: ScalarIndexer) -> IntervalOrNA: ... @overload @@ -100,7 +99,6 @@ class IntervalArray(IntervalMixin, ExtensionArray): def mid(self) -> Index: ... @property def is_non_overlapping_monotonic(self) -> bool: ... - def __array__(self, dtype=...) -> np_1darray: ... def __arrow_array__(self, type=...): ... def to_tuples(self, na_tuple: bool = True): ... def repeat(self, repeats, axis: Axis | None = ...): ... diff --git a/pandas-stubs/core/arrays/masked.pyi b/pandas-stubs/core/arrays/masked.pyi index 20cbdcf95..160fad580 100644 --- a/pandas-stubs/core/arrays/masked.pyi +++ b/pandas-stubs/core/arrays/masked.pyi @@ -23,7 +23,6 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin): @overload def __getitem__(self, item: SequenceIndexer) -> Self: ... def __iter__(self): ... - def __len__(self) -> int: ... def __invert__(self): ... def to_numpy( self, @@ -32,7 +31,6 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin): na_value: Scalar = ..., ) -> np.ndarray: ... __array_priority__: int = ... - def __array__(self, dtype=...) -> np.ndarray: ... def __arrow_array__(self, type=...): ... def isna(self): ... @property diff --git a/pandas-stubs/core/arrays/numpy_.pyi b/pandas-stubs/core/arrays/numpy_.pyi index eab689c0b..760d82e84 100644 --- a/pandas-stubs/core/arrays/numpy_.pyi +++ b/pandas-stubs/core/arrays/numpy_.pyi @@ -1,5 +1,3 @@ -from typing import Any - import numpy as np from numpy.lib.mixins import NDArrayOperatorsMixin from pandas.core.arrays.base import ( @@ -15,5 +13,4 @@ class PandasDtype(ExtensionDtype): @property def itemsize(self) -> int: ... -class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin): - def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ... +class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin): ... diff --git a/pandas-stubs/core/arrays/period.pyi b/pandas-stubs/core/arrays/period.pyi index ca5c79944..a04caab05 100644 --- a/pandas-stubs/core/arrays/period.pyi +++ b/pandas-stubs/core/arrays/period.pyi @@ -1,4 +1,3 @@ -import numpy as np from pandas import PeriodDtype from pandas.core.arrays.datetimelike import ( DatelikeOps, @@ -13,7 +12,6 @@ class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps): def __init__(self, values, freq=..., dtype=..., copy: bool = ...) -> None: ... @property def dtype(self) -> PeriodDtype: ... - def __array__(self, dtype=...) -> np.ndarray: ... def __arrow_array__(self, type=...): ... year: int = ... month: int = ... diff --git a/pandas-stubs/core/arrays/sparse/array.pyi b/pandas-stubs/core/arrays/sparse/array.pyi index 433a56dfd..be5c76c34 100644 --- a/pandas-stubs/core/arrays/sparse/array.pyi +++ b/pandas-stubs/core/arrays/sparse/array.pyi @@ -5,7 +5,6 @@ from typing import ( overload, ) -import numpy as np from pandas.core.arrays import ( ExtensionArray, ExtensionOpsMixin, @@ -33,7 +32,6 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin): ) -> None: ... @classmethod def from_spmatrix(cls, data): ... - def __array__(self, dtype=..., copy=...) -> np.ndarray: ... def __setitem__(self, key, value) -> None: ... @property def sp_index(self): ... @@ -47,7 +45,6 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin): def fill_value(self, value) -> None: ... @property def kind(self) -> str: ... - def __len__(self) -> int: ... @property def nbytes(self) -> int: ... @property @@ -78,5 +75,4 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin): def mean(self, axis: int = ..., *args: Any, **kwargs: Any): ... @property def T(self): ... - def __array_ufunc__(self, ufunc, method, *inputs, **kwargs: Any): ... def __abs__(self): ... diff --git a/pandas-stubs/core/indexes/category.pyi b/pandas-stubs/core/indexes/category.pyi index 22475842b..a9b2e4bf2 100644 --- a/pandas-stubs/core/indexes/category.pyi +++ b/pandas-stubs/core/indexes/category.pyi @@ -13,6 +13,7 @@ from typing_extensions import Self from pandas._typing import ( S1, DtypeArg, + np_1darray, ) class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate): @@ -35,7 +36,7 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate): def __contains__(self, key) -> bool: ... def __array__( self, dtype: DtypeArg = ..., copy: bool | None = ... - ) -> np.ndarray: ... + ) -> np_1darray: ... @property def is_unique(self) -> bool: ... @property diff --git a/pandas-stubs/core/indexes/range.pyi b/pandas-stubs/core/indexes/range.pyi index 5f5e13013..4cb9ab35d 100644 --- a/pandas-stubs/core/indexes/range.pyi +++ b/pandas-stubs/core/indexes/range.pyi @@ -74,7 +74,6 @@ class RangeIndex(_IndexSubclassBase[int, np.int64]): return_indexers: bool = ..., sort: bool = ..., ): ... - def __len__(self) -> int: ... @property def size(self) -> int: ... def __floordiv__(self, other): ... diff --git a/pandas-stubs/plotting/_misc.pyi b/pandas-stubs/plotting/_misc.pyi index b1fdeb92a..5a5568726 100644 --- a/pandas-stubs/plotting/_misc.pyi +++ b/pandas-stubs/plotting/_misc.pyi @@ -49,7 +49,7 @@ def radviz( ax: Axes | None = None, color: _Color | Sequence[_Color] | None = None, colormap: str | Colormap | None = None, - **kwds, + **kwds: Any, ) -> Axes: ... def andrews_curves( frame: DataFrame, @@ -65,7 +65,7 @@ def bootstrap_plot( fig: Figure | None = None, size: int = 50, samples: int = 500, - **kwds, + **kwds: Any, ) -> Figure: ... def parallel_coordinates( frame: DataFrame, @@ -81,7 +81,9 @@ def parallel_coordinates( sort_labels: bool = False, **kwargs: Any, ) -> Axes: ... -def lag_plot(series: Series, lag: int = 1, ax: Axes | None = None, **kwds) -> Axes: ... +def lag_plot( + series: Series, lag: int = 1, ax: Axes | None = None, **kwds: Any +) -> Axes: ... def autocorrelation_plot( series: Series, ax: Axes | None = None, **kwargs: Any ) -> Axes: ... diff --git a/pyproject.toml b/pyproject.toml index 78270bfa0..513077c2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -178,7 +178,6 @@ fix = true [tool.ruff.lint] extend-select = ["ALL"] ignore = [ - # The following rules are ignored permanently for good reasons "COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com "D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d "E501", # handled by black https://docs.astral.sh/ruff/rules/line-too-long/ @@ -200,14 +199,11 @@ ignore = [ "PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/ "PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ "TD003", # https://docs.astral.sh/ruff/rules/missing-todo-link/ - "ERA001", "ANN", "PLR0402", "PLC0105" + "ERA001", "ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "PLR0402", "PLC0105" ] "scripts/*" = [ - # The following rules are ignored permanently for good reasons "EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em "S603", # https://docs.astral.sh/ruff/rules/subprocess-without-shell-equals-true/ - # The following rules are ignored temporarily. Either fix them or move to the permanent list above. - "TRY", "PT", "BLE" ] "tests/*" = [ # The following rules are ignored permanently for good reasons @@ -223,7 +219,7 @@ ignore = [ "A001", # https://docs.astral.sh/ruff/rules/builtin-variable-shadowing/ "PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ "SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ - "ANN001", "ANN002", "ANN201", "ANN202", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901" + "ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901" ] "tests/test_io.py" = [ # The following rules are ignored permanently for good reasons diff --git a/scripts/_job.py b/scripts/_job.py index 7a5c175b9..cc0d6aa5e 100644 --- a/scripts/_job.py +++ b/scripts/_job.py @@ -25,7 +25,7 @@ def __rollback_job(steps: deque[Step]) -> None: logger.warning(f"Undoing: {step.name}") try: step.rollback() - except Exception: + except Exception: # noqa: BLE001 logger.error( f"Rollback of Step: '{step.name}' failed! The project could be in a unstable mode." ) @@ -47,7 +47,7 @@ def run_job(steps: list[Step]) -> None: rollback_steps.append(step) step.run() - except Exception: + except Exception: # noqa: BLE001 logger.error(f"Step: '{step.name}' failed!") __rollback_job(rollback_steps) failed = True diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py index eb7412b9a..afa6a0e16 100644 --- a/scripts/test/__init__.py +++ b/scripts/test/__init__.py @@ -22,9 +22,9 @@ def test( - src: bool = False, - dist: bool = False, - type_checker: Literal["", "mypy", "pyright"] = "", + src: bool = False, # noqa: PT028 + dist: bool = False, # noqa: PT028 + type_checker: Literal["", "mypy", "pyright"] = "", # noqa: PT028 ) -> None: steps = [] if src: diff --git a/scripts/test/run.py b/scripts/test/run.py index a876d5bcc..721baffe3 100644 --- a/scripts/test/run.py +++ b/scripts/test/run.py @@ -62,7 +62,9 @@ def rename_src() -> None: if Path(r"pandas-stubs").exists(): Path(r"pandas-stubs").rename("_pandas-stubs") else: - raise FileNotFoundError("'pandas-stubs' folder does not exists.") + raise FileNotFoundError( # noqa: TRY003 + "'pandas-stubs' folder does not exists." + ) def mypy_dist() -> None: @@ -84,7 +86,9 @@ def restore_src() -> None: if Path(r"_pandas-stubs").exists(): Path(r"_pandas-stubs").rename("pandas-stubs") else: - raise FileNotFoundError("'_pandas-stubs' folder does not exists.") + raise FileNotFoundError( # noqa: TRY003 + "'_pandas-stubs' folder does not exists." + ) def nightly_pandas() -> None: diff --git a/tests/extension/decimal/array.py b/tests/extension/decimal/array.py index ad3a5ae17..3f8aed95d 100644 --- a/tests/extension/decimal/array.py +++ b/tests/extension/decimal/array.py @@ -1,10 +1,14 @@ from __future__ import annotations from builtins import type as type_t +from collections.abc import Callable import decimal import numbers import sys -from typing import Any +from typing import ( + Any, + cast, +) import numpy as np from pandas.api.extensions import ( @@ -125,7 +129,9 @@ def to_numpy( result = np.asarray([round(x, decimals) for x in result]) return result - def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs: Any): + def __array_ufunc__( + self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any + ): # if not all( isinstance(t, self._HANDLED_TYPES + (DecimalArray,)) for t in inputs @@ -147,7 +153,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs: Any): if result is not NotImplemented: return result - def reconstruct(x): + def reconstruct(x) -> decimal.Decimal | numbers.Number | DecimalArray: if isinstance(x, (decimal.Decimal, numbers.Number)): return x return DecimalArray._from_sequence(x) @@ -220,10 +226,10 @@ def isna(self): return np.array([x.is_nan() for x in self._data], dtype=bool) @property - def _na_value(self): + def _na_value(self) -> decimal.Decimal: return decimal.Decimal("NaN") - def _formatter(self, boxed=False): + def _formatter(self, boxed=False) -> Callable[..., str]: if boxed: return "Decimal: {}".format return repr @@ -232,7 +238,7 @@ def _formatter(self, boxed=False): def _concat_same_type(cls, to_concat): return cls(np.concatenate([x._data for x in to_concat])) - def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any): + def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any) -> Any: if skipna: # If we don't have any NAs, we can ignore skipna if self.isna().any(): @@ -251,9 +257,9 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any): ) from err return op(axis=0) - def _cmp_method(self, other, op): + def _cmp_method(self, other, op) -> np.ndarray[tuple[int], np.dtype[np.bool_]]: # For use with OpsMixin - def convert_values(param): + def convert_values(param) -> ExtensionArray | list[Any]: if isinstance(param, ExtensionArray) or is_list_like(param): ovalues = param else: @@ -268,7 +274,9 @@ def convert_values(param): # a TypeError should be raised res = [op(a, b) for (a, b) in zip(lvalues, rvalues)] - return np.asarray(res, dtype=bool) + return cast( + np.ndarray[tuple[int], np.dtype[np.bool_]], np.asarray(res, dtype=bool) + ) def value_counts(self, dropna: bool = True): from pandas.core.algorithms import value_counts diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 0c9aad503..06763f3a2 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -73,6 +73,8 @@ ) if TYPE_CHECKING: + from _typeshed import SupportsMul + from tests import ( BooleanDtypeArg, BytesDtypeArg, @@ -110,6 +112,9 @@ "T", # unicode-string (variable-width) ] +T = TypeVar("T") +T_co = TypeVar("T_co", covariant=True) + def test_types_init() -> None: pd.Series(1) @@ -2125,7 +2130,6 @@ def test_AnyArrayLike_and_clip() -> None: def test_pandera_generic() -> None: # GH 471 - T = TypeVar("T") class MySeries(pd.Series, Generic[T]): def __new__(cls, *args: Any, **kwargs: Any) -> Self: @@ -3151,7 +3155,7 @@ def test_series_to_string_float_fmt() -> None: ) check(assert_type(sr.to_string(), str), str) - def _formatter(x) -> str: + def _formatter(x: float) -> str: return f"{x:.2f}" check(assert_type(sr.to_string(float_format=_formatter), str), str) @@ -3178,7 +3182,7 @@ def cond(x: int) -> bool: check(assert_type(s.mask(cond, 10), "pd.Series[int]"), pd.Series, np.integer) # Test case with a boolean condition and a callable - def double(x): + def double(x: SupportsMul[int, T_co]) -> T_co: return x * 2 check(assert_type(s.mask(s > 3, double), "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/test_frame.py b/tests/test_frame.py index 612371842..7bb865e10 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -25,6 +25,7 @@ TYPE_CHECKING, Any, Generic, + Protocol, TypeAlias, TypedDict, TypeVar, @@ -82,7 +83,7 @@ DF = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}) -def getCols(k) -> str: +def getCols(k: int) -> str: return string.ascii_uppercase[:k] @@ -90,7 +91,7 @@ def makeStringIndex(k: int = 10) -> pd.Index: return pd.Index(rands_array(nchars=10, size=k), name=None) -def rands_array(nchars, size: int) -> np.ndarray: +def rands_array(nchars: int, size: int) -> npt.NDArray[Any]: chars = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1)) retval = ( np.random.default_rng(2) @@ -1712,7 +1713,12 @@ def test_types_groupby_agg() -> None: agg_dict1 = {"col2": "min", "col3": "max", 0: "sum"} check(assert_type(df.groupby("col1").agg(agg_dict1), pd.DataFrame), pd.DataFrame) - def wrapped_min(x: Any) -> Any: + T_co = TypeVar("T_co", covariant=True) + + class SupportsMin(Protocol[T_co]): + def min(self) -> T_co: ... + + def wrapped_min(x: SupportsMin[T_co]) -> T_co: return x.min() with pytest_warns_bounded( @@ -2142,7 +2148,7 @@ def test_dataframe_to_string_float_fmt() -> None: ) check(assert_type(df.to_string(), str), str) - def _formatter(x) -> str: + def _formatter(x: float) -> str: return f"{x:.2f}" check(assert_type(df.to_string(float_format=_formatter), str), str) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 46d5b37a4..20a4ab153 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -25,7 +25,7 @@ @pytest.fixture(autouse=True) -def autouse_mpl_cleanup(mpl_cleanup) -> None: +def autouse_mpl_cleanup(mpl_cleanup: None) -> None: pass @@ -189,22 +189,22 @@ def close_figures() -> None: IRIS_DF = pd.read_csv(io.StringIO(IRIS)) -def test_andrews_curves(close_figures) -> None: +def test_andrews_curves(close_figures: None) -> None: check(assert_type(pd.plotting.andrews_curves(IRIS_DF, "Name"), Axes), Axes) -def test_autocorrelation_plot(close_figures) -> None: +def test_autocorrelation_plot(close_figures: None) -> None: spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000) s = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing)) check(assert_type(pd.plotting.autocorrelation_plot(s), Axes), Axes) -def test_bootstrap_plot(close_figures) -> None: +def test_bootstrap_plot(close_figures: None) -> None: s = pd.Series(np.random.uniform(size=100)) check(assert_type(pd.plotting.bootstrap_plot(s), Figure), Figure) -def test_boxplot(close_figures) -> None: +def test_boxplot(close_figures: None) -> None: np.random.seed(1234) df = pd.DataFrame(np.random.randn(10, 4), columns=["Col1", "Col2", "Col3", "Col4"]) check( @@ -213,19 +213,19 @@ def test_boxplot(close_figures) -> None: ) -def test_reg_dereg(close_figures) -> None: +def test_reg_dereg(close_figures: None) -> None: check(assert_type(register_matplotlib_converters(), None), type(None)) check(assert_type(deregister_matplotlib_converters(), None), type(None)) -def test_lag_plot(close_figures) -> None: +def test_lag_plot(close_figures: None) -> None: np.random.seed(5) x = np.cumsum(np.random.normal(loc=1, scale=5, size=50)) s = pd.Series(x) check(assert_type(pd.plotting.lag_plot(s, lag=1), Axes), Axes) -def test_plot_parallel_coordinates(close_figures) -> None: +def test_plot_parallel_coordinates(close_figures: None) -> None: check( assert_type( pd.plotting.parallel_coordinates( @@ -237,11 +237,11 @@ def test_plot_parallel_coordinates(close_figures) -> None: ) -def test_plot_params(close_figures) -> None: +def test_plot_params(close_figures: None) -> None: check(assert_type(pd.plotting.plot_params, dict[str, Any]), dict) -def test_radviz(close_figures) -> None: +def test_radviz(close_figures: None) -> None: df = pd.DataFrame( { "SepalLength": [6.5, 7.7, 5.1, 5.8, 7.6, 5.0, 5.4, 4.6, 6.7, 4.6], @@ -265,7 +265,7 @@ def test_radviz(close_figures) -> None: check(assert_type(pd.plotting.radviz(df, "Category"), Axes), Axes) -def test_scatter_matrix(close_figures) -> None: +def test_scatter_matrix(close_figures: None) -> None: df = pd.DataFrame(np.random.randn(1000, 4), columns=["A", "B", "C", "D"]) check( assert_type( @@ -276,7 +276,7 @@ def test_scatter_matrix(close_figures) -> None: ) -def test_table(close_figures) -> None: +def test_table(close_figures: None) -> None: df = pd.DataFrame(np.random.randn(1000, 4), columns=["A", "B", "C", "D"]) _, ax = plt.subplots(1, 1) check(assert_type(pd.plotting.table(ax, df), Table), Table) @@ -302,7 +302,7 @@ def test_plot_line() -> None: ) -def test_plot_area(close_figures) -> None: +def test_plot_area(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.area(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="area"), Axes), Axes) check( @@ -321,7 +321,7 @@ def test_plot_area(close_figures) -> None: ) -def test_plot_bar(close_figures) -> None: +def test_plot_bar(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.bar(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="bar"), Axes), Axes) check( @@ -340,7 +340,7 @@ def test_plot_bar(close_figures) -> None: ) -def test_plot_barh(close_figures) -> None: +def test_plot_barh(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.barh(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="barh"), Axes), Axes) check( @@ -359,7 +359,7 @@ def test_plot_barh(close_figures) -> None: ) -def test_plot_box(close_figures) -> None: +def test_plot_box(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.box(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="box"), Axes), Axes) check( @@ -378,7 +378,7 @@ def test_plot_box(close_figures) -> None: ) -def test_plot_density(close_figures) -> None: +def test_plot_density(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.density(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="density"), Axes), Axes) check( @@ -397,7 +397,7 @@ def test_plot_density(close_figures) -> None: ) -def test_plot_hexbin(close_figures) -> None: +def test_plot_hexbin(close_figures: None) -> None: check( assert_type(IRIS_DF.plot.hexbin(x="SepalLength", y="SepalWidth"), Axes), Axes, @@ -422,7 +422,7 @@ def test_plot_hexbin(close_figures) -> None: ) -def test_plot_hist(close_figures) -> None: +def test_plot_hist(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.hist(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="hist"), Axes), Axes) check( @@ -441,7 +441,7 @@ def test_plot_hist(close_figures) -> None: ) -def test_plot_kde(close_figures) -> None: +def test_plot_kde(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.kde(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="kde"), Axes), Axes) check( @@ -460,7 +460,7 @@ def test_plot_kde(close_figures) -> None: ) -def test_plot_pie(close_figures) -> None: +def test_plot_pie(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.pie(y="SepalLength"), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="pie", y="SepalLength"), Axes), Axes) check( @@ -480,7 +480,7 @@ def test_plot_pie(close_figures) -> None: ) -def test_plot_scatter(close_figures) -> None: +def test_plot_scatter(close_figures: None) -> None: check( assert_type(IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth"), Axes), Axes, @@ -509,7 +509,7 @@ def test_plot_scatter(close_figures) -> None: ) -def test_plot_keywords(close_figures) -> None: +def test_plot_keywords(close_figures: None) -> None: _, ax = plt.subplots(1, 1) df = IRIS_DF.iloc[:, :3].abs() check( @@ -593,7 +593,7 @@ def test_plot_subplot_changes_150() -> None: ) -def test_grouped_dataframe_boxplot(close_figures) -> None: +def test_grouped_dataframe_boxplot(close_figures: None) -> None: tuples = list(itertools.product(range(10), range(2))) index = pd.MultiIndex.from_tuples(tuples, names=["lvl0", "lvl1"]) df = pd.DataFrame( @@ -622,7 +622,7 @@ def test_grouped_dataframe_boxplot(close_figures) -> None: ) -def test_grouped_dataframe_boxplot_single(close_figures) -> None: +def test_grouped_dataframe_boxplot_single(close_figures: None) -> None: """ Test with pandas 2.2.3 separated to make it pass. @@ -670,7 +670,7 @@ def test_grouped_dataframe_boxplot_single(close_figures) -> None: check(assert_type(grouped.boxplot(subplots=bool(0.5)), Axes | Series), Series) -def test_grouped_dataframe_hist(close_figures) -> None: +def test_grouped_dataframe_hist(close_figures: None) -> None: df = IRIS_DF.iloc[:50] grouped = df.groupby("Name") check(assert_type(grouped.hist(), Series), Series) @@ -694,7 +694,7 @@ def test_grouped_dataframe_hist(close_figures) -> None: ) -def test_grouped_dataframe_hist_str(close_figures) -> None: +def test_grouped_dataframe_hist_str(close_figures: None) -> None: df = IRIS_DF.iloc[:50] grouped = df.groupby("Name") check(assert_type(grouped.hist(), Series), Series) @@ -718,7 +718,7 @@ def test_grouped_dataframe_hist_str(close_figures) -> None: ) -def test_grouped_series_hist(close_figures) -> None: +def test_grouped_series_hist(close_figures: None) -> None: multi_index = pd.MultiIndex.from_tuples([(0, 0), (0, 1), (1, 0)], names=["a", "b"]) s = pd.Series([0, 1, 2], index=multi_index, dtype=int) grouped = s.groupby(level=0)