From 298677f59eaf1617012d41ef4f27cc9fa3a84d56 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 26 May 2024 17:38:44 +0200 Subject: [PATCH 1/5] Remove pandas 2.0 deprecations from NDFrame and subclasses --- pandas-stubs/core/frame.pyi | 15 +-------------- pandas-stubs/core/generic.pyi | 18 ++---------------- pandas-stubs/core/series.pyi | 13 +------------ 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 7331c0d19..04314d144 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -668,7 +668,6 @@ class DataFrame(NDFrame, OpsMixin): allow_duplicates: _bool = ..., ) -> None: ... def assign(self, **kwargs) -> DataFrame: ... - def lookup(self, row_labels: Sequence, col_labels: Sequence) -> np.ndarray: ... def align( self, other: NDFrameT, @@ -1691,7 +1690,6 @@ class DataFrame(NDFrame, OpsMixin): percentiles: list[float] | None = ..., include: Literal["all"] | list[Dtype] | None = ..., exclude: list[Dtype] | None = ..., - datetime_is_numeric: _bool | None = ..., ) -> DataFrame: ... def div( self, @@ -1850,7 +1848,6 @@ class DataFrame(NDFrame, OpsMixin): inplace: _bool = ..., axis: Axis | None = ..., level: Level | None = ..., - try_cast: _bool = ..., ) -> DataFrame: ... def max( self, @@ -2107,7 +2104,6 @@ class DataFrame(NDFrame, OpsMixin): numeric_only: _bool = ..., **kwargs, ) -> Series: ... - def slice_shift(self, periods: int = ..., axis: Axis = ...) -> DataFrame: ... def squeeze(self, axis: Axis | None = ...): ... def std( self, @@ -2143,14 +2139,7 @@ class DataFrame(NDFrame, OpsMixin): ) -> Series: ... def swapaxes(self, axis1: Axis, axis2: Axis, copy: _bool = ...) -> DataFrame: ... def tail(self, n: int = ...) -> DataFrame: ... - def take( - self, - indices: list, - axis: Axis = ..., - is_copy: _bool | None = ..., - **kwargs, - ) -> DataFrame: ... - def tshift(self, periods: int = ..., freq=..., axis: Axis = ...) -> DataFrame: ... + def take(self, indices: list, axis: Axis = ..., **kwargs) -> DataFrame: ... def to_clipboard( self, excel: _bool = ..., sep: _str | None = ..., **kwargs ) -> None: ... @@ -2289,7 +2278,6 @@ class DataFrame(NDFrame, OpsMixin): axis: Axis | None = ..., copy: _bool = ..., ) -> DataFrame: ... - # def tshift def tz_convert( self, tz, @@ -2329,7 +2317,6 @@ class DataFrame(NDFrame, OpsMixin): inplace: _bool = ..., axis: Axis | None = ..., level: Level | None = ..., - try_cast: _bool = ..., ) -> DataFrame: ... # Move from generic because Series is Generic and it returns Series[bool] there def __invert__(self) -> DataFrame: ... diff --git a/pandas-stubs/core/generic.pyi b/pandas-stubs/core/generic.pyi index e1032a1d2..7af030803 100644 --- a/pandas-stubs/core/generic.pyi +++ b/pandas-stubs/core/generic.pyi @@ -197,7 +197,6 @@ class NDFrame(indexing.IndexingMixin): self, buf: FilePath | WriteBuffer[str], columns: list[_str] | None = ..., - col_space: int | None = ..., header: _bool | list[_str] = ..., index: _bool = ..., na_rep: _str = ..., @@ -223,7 +222,6 @@ class NDFrame(indexing.IndexingMixin): self, buf: None = ..., columns: list[_str] | None = ..., - col_space: int | None = ..., header: _bool | list[_str] = ..., index: _bool = ..., na_rep: _str = ..., @@ -294,9 +292,7 @@ class NDFrame(indexing.IndexingMixin): errors: _str = ..., storage_options: StorageOptions = ..., ) -> _str: ... - def take( - self, indices, axis=..., is_copy: _bool | None = ..., **kwargs - ) -> Self: ... + def take(self, indices, axis=..., **kwargs) -> Self: ... def __delitem__(self, idx: Hashable) -> None: ... def reindex_like( self, @@ -474,7 +470,6 @@ class NDFrame(indexing.IndexingMixin): inplace: _bool = ..., axis=..., level=..., - try_cast: _bool = ..., ): ... def mask( self, @@ -484,11 +479,8 @@ class NDFrame(indexing.IndexingMixin): inplace: _bool = ..., axis=..., level=..., - try_cast: _bool = ..., ): ... def shift(self, periods=..., freq=..., axis=..., fill_value=...) -> Self: ... - def slice_shift(self, periods: int = ..., axis=...) -> Self: ... - def tshift(self, periods: int = ..., freq=..., axis=...) -> Self: ... def truncate(self, before=..., after=..., axis=..., copy: _bool = ...) -> Self: ... def tz_convert(self, tz, axis=..., level=..., copy: _bool = ...) -> Self: ... def tz_localize( @@ -501,13 +493,7 @@ class NDFrame(indexing.IndexingMixin): nonexistent: str = ..., ) -> Self: ... def abs(self) -> Self: ... - def describe( - self, - percentiles=..., - include=..., - exclude=..., - datetime_is_numeric: _bool | None = ..., - ) -> NDFrame: ... + def describe(self, percentiles=..., include=..., exclude=...) -> NDFrame: ... def pct_change( self, periods=..., fill_method=..., limit=..., freq=..., **kwargs ) -> Self: ... diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 8da1c6ae8..900ca9b9c 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -372,11 +372,7 @@ class Series(IndexOpsMixin[S1], NDFrame): @property def axes(self) -> list: ... def take( - self, - indices: Sequence, - axis: AxisIndex = ..., - is_copy: _bool | None = ..., - **kwargs, + self, indices: Sequence, axis: AxisIndex = ..., **kwargs ) -> Series[S1]: ... def __getattr__(self, name: _str) -> S1: ... @overload @@ -1429,7 +1425,6 @@ class Series(IndexOpsMixin[S1], NDFrame): inplace: _bool = ..., axis: AxisIndex | None = ..., level: Level | None = ..., - try_cast: _bool = ..., ) -> Series[S1]: ... def mask( self, @@ -1445,11 +1440,6 @@ class Series(IndexOpsMixin[S1], NDFrame): inplace: _bool = ..., axis: AxisIndex | None = ..., level: Level | None = ..., - try_cast: _bool = ..., - ) -> Series[S1]: ... - def slice_shift(self, periods: int = ..., axis: AxisIndex = ...) -> Series[S1]: ... - def tshift( - self, periods: int = ..., freq=..., axis: AxisIndex = ... ) -> Series[S1]: ... def truncate( self, @@ -1480,7 +1470,6 @@ class Series(IndexOpsMixin[S1], NDFrame): percentiles: list[float] | None = ..., include: Literal["all"] | list[S1] | None = ..., exclude: S1 | list[S1] | None = ..., - datetime_is_numeric: _bool | None = ..., ) -> Series[S1]: ... def pct_change( self, From 16d331c52a26473f34f667da82aa39ff32d211da Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 26 May 2024 17:46:36 +0200 Subject: [PATCH 2/5] Fix pyright --- pandas-stubs/core/groupby/generic.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From f324108eb836c840dff86f0a51a8cb832dfd4afe Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 26 May 2024 17:57:50 +0200 Subject: [PATCH 3/5] Fix matplotlib warnings --- tests/test_plotting.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) 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 624511983e575aada0f6c24025e2fc29c15b3136 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Wed, 29 May 2024 20:32:12 +0200 Subject: [PATCH 4/5] Revert "Fix matplotlib warnings" This reverts commit f324108eb836c840dff86f0a51a8cb832dfd4afe. --- tests/test_plotting.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) 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): From a2188046d1bedcda7f3013f6444f4b0492a90c0c Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Wed, 29 May 2024 20:32:27 +0200 Subject: [PATCH 5/5] Revert "Fix pyright" This reverts commit 16d331c52a26473f34f667da82aa39ff32d211da. --- pandas-stubs/core/groupby/generic.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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,