From 6ecbab99c37bcb83310eaaa04c24e9c54c45fbf5 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 26 May 2024 18:07:08 +0200 Subject: [PATCH 1/3] Fix CI from PR 930 --- pandas-stubs/core/groupby/generic.pyi | 2 +- tests/test_plotting.py | 31 ++++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pandas-stubs/core/groupby/generic.pyi b/pandas-stubs/core/groupby/generic.pyi index 37f3c0dcc..65522a9b8 100644 --- a/pandas-stubs/core/groupby/generic.pyi +++ b/pandas-stubs/core/groupby/generic.pyi @@ -207,7 +207,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT]): ) -> DataFrame: ... # error: overload 1 overlaps overload 2 because of different return types @overload - def aggregate(self, func: Literal["size"]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + def aggregate(self, func: Literal["size"]) -> Series: ... # type: ignore[overload-overlap] @overload def aggregate( self, diff --git a/tests/test_plotting.py b/tests/test_plotting.py index e6ebcec20..b541c4432 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -486,22 +486,23 @@ def test_plot_scatter(close_figures) -> None: ), Axes, ) - check( - assert_type( - IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth", subplots=True), - npt.NDArray[np.object_], - ), - np.ndarray, - ) - check( - assert_type( - IRIS_DF.plot( - x="SepalLength", y="SepalWidth", subplots=True, kind="scatter" + with pytest.warns(UserWarning): + check( + assert_type( + IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth", subplots=True), + npt.NDArray[np.object_], ), - npt.NDArray[np.object_], - ), - np.ndarray, - ) + np.ndarray, + ) + check( + assert_type( + IRIS_DF.plot( + x="SepalLength", y="SepalWidth", subplots=True, kind="scatter" + ), + npt.NDArray[np.object_], + ), + np.ndarray, + ) def test_plot_keywords(close_figures): From c1c6f75ad22ba67028e80746e812cdd0afdc1e7c Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 26 May 2024 18:15:20 +0200 Subject: [PATCH 2/3] pandas 2.0 removals in core/arrays --- pandas-stubs/core/arrays/categorical.pyi | 79 +++--------------------- pandas-stubs/core/arrays/datetimes.pyi | 2 - 2 files changed, 7 insertions(+), 74 deletions(-) diff --git a/pandas-stubs/core/arrays/categorical.pyi b/pandas-stubs/core/arrays/categorical.pyi index 2d0b16359..cb0aeaa42 100644 --- a/pandas-stubs/core/arrays/categorical.pyi +++ b/pandas-stubs/core/arrays/categorical.pyi @@ -2,11 +2,7 @@ from collections.abc import ( Callable, Sequence, ) -from typing import ( - Any, - Literal, - overload, -) +from typing import Any import numpy as np from pandas import Series @@ -48,7 +44,6 @@ class Categorical(ExtensionArray): def dtype(self) -> CategoricalDtype: ... def astype(self, dtype: Dtype, copy: bool = ...) -> ArrayLike: ... def size(self) -> int: ... - def itemsize(self) -> int: ... def tolist(self) -> list[Scalar]: ... to_list = ... @classmethod @@ -65,72 +60,16 @@ class Categorical(ExtensionArray): def set_ordered(self, value) -> Categorical: ... def as_ordered(self) -> Categorical: ... def as_unordered(self) -> Categorical: ... - @overload - def set_categories( - self, new_categories, ordered=..., rename: bool = ..., *, inplace: Literal[True] - ) -> None: ... - @overload - def set_categories( - self, - new_categories, - ordered=..., - rename: bool = ..., - inplace: Literal[False] = ..., - ) -> Categorical: ... - @overload def set_categories( - self, new_categories, ordered=..., rename: bool = ..., inplace: bool = ... - ) -> Categorical | None: ... - @overload - def rename_categories(self, new_categories, inplace: Literal[True]) -> None: ... - @overload - def rename_categories( - self, new_categories, inplace: Literal[False] = ... + self, new_categories, ordered: bool | None = ..., rename: bool = ... ) -> Categorical: ... - @overload - def rename_categories( - self, new_categories, inplace: bool = ... - ) -> Categorical | None: ... - @overload - def reorder_categories( - self, new_categories, ordered=..., *, inplace: Literal[True] - ) -> None: ... - @overload + def rename_categories(self, new_categories) -> Categorical: ... def reorder_categories( - self, new_categories, ordered=..., inplace: Literal[False] = ... - ) -> Categorical: ... - @overload - def reorder_categories( - self, new_categories, ordered=..., inplace: bool = ... - ) -> Categorical | None: ... - @overload - def add_categories(self, new_categories, inplace: Literal[True]) -> None: ... - @overload - def add_categories( - self, new_categories, inplace: Literal[False] = ... - ) -> Categorical: ... - @overload - def add_categories( - self, new_categories, inplace: bool = ... - ) -> Categorical | None: ... - @overload - def remove_categories(self, removals, inplace: Literal[True]) -> None: ... - @overload - def remove_categories( - self, removals, inplace: Literal[False] = ... - ) -> Categorical: ... - @overload - def remove_categories( - self, removals, inplace: bool = ... - ) -> Categorical | None: ... - @overload - def remove_unused_categories(self, inplace: Literal[True]) -> None: ... - @overload - def remove_unused_categories( - self, inplace: Literal[False] = ... + self, new_categories, ordered: bool | None = ... ) -> Categorical: ... - @overload - def remove_unused_categories(self, inplace: bool = ...) -> Categorical | None: ... + def add_categories(self, new_categories) -> Categorical: ... + def remove_categories(self, removals) -> Categorical: ... + def remove_unused_categories(self) -> Categorical: ... def map(self, mapper): ... def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... @@ -161,12 +100,10 @@ class Categorical(ExtensionArray): self, *, inplace: bool = ..., ascending: bool = ..., na_position: str = ... ): ... def view(self, dtype=...): ... - def to_dense(self): ... def fillna(self, value=..., method=..., limit=...): ... def take( self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=... ) -> Categorical: ... - def take_nd(self, indexer, allow_fill: bool = ..., fill_value=...): ... def __len__(self) -> int: ... def __iter__(self): ... def __contains__(self, key) -> bool: ... @@ -174,10 +111,8 @@ class Categorical(ExtensionArray): def __setitem__(self, key, value) -> None: ... def min(self, *, skipna: bool = ...): ... def max(self, *, skipna: bool = ...): ... - def mode(self, dropna: bool = ...): ... def unique(self): ... def equals(self, other): ... - def is_dtype_equal(self, other): ... def describe(self): ... def repeat(self, repeats, axis=...): ... def isin(self, values): ... diff --git a/pandas-stubs/core/arrays/datetimes.pyi b/pandas-stubs/core/arrays/datetimes.pyi index 5afcb6898..7e4c7d7a1 100644 --- a/pandas-stubs/core/arrays/datetimes.pyi +++ b/pandas-stubs/core/arrays/datetimes.pyi @@ -50,8 +50,6 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps): second = ... microsecond = ... nanosecond = ... - weekofyear = ... - week = ... dayofweek = ... weekday = ... dayofyear = ... From f1ea0702a509dd14d6cdf46a2018f9a4a9ad8663 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Wed, 29 May 2024 20:37:56 +0200 Subject: [PATCH 3/3] Revert "Fix CI from PR 930" This reverts commit 6ecbab99c37bcb83310eaaa04c24e9c54c45fbf5. --- pandas-stubs/core/groupby/generic.pyi | 2 +- tests/test_plotting.py | 31 +++++++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pandas-stubs/core/groupby/generic.pyi b/pandas-stubs/core/groupby/generic.pyi index 65522a9b8..37f3c0dcc 100644 --- a/pandas-stubs/core/groupby/generic.pyi +++ b/pandas-stubs/core/groupby/generic.pyi @@ -207,7 +207,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT]): ) -> DataFrame: ... # error: overload 1 overlaps overload 2 because of different return types @overload - def aggregate(self, func: Literal["size"]) -> Series: ... # type: ignore[overload-overlap] + def aggregate(self, func: Literal["size"]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] @overload def aggregate( self, diff --git a/tests/test_plotting.py b/tests/test_plotting.py index b541c4432..e6ebcec20 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -486,23 +486,22 @@ def test_plot_scatter(close_figures) -> None: ), Axes, ) - with pytest.warns(UserWarning): - check( - assert_type( - IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth", subplots=True), - npt.NDArray[np.object_], - ), - np.ndarray, - ) - check( - assert_type( - IRIS_DF.plot( - x="SepalLength", y="SepalWidth", subplots=True, kind="scatter" - ), - npt.NDArray[np.object_], + check( + assert_type( + IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth", subplots=True), + npt.NDArray[np.object_], + ), + np.ndarray, + ) + check( + assert_type( + IRIS_DF.plot( + x="SepalLength", y="SepalWidth", subplots=True, kind="scatter" ), - np.ndarray, - ) + npt.NDArray[np.object_], + ), + np.ndarray, + ) def test_plot_keywords(close_figures):