From ce186d3d39509fb1b10bc8710de80b1b35e44991 Mon Sep 17 00:00:00 2001 From: noah-asing <7989798+noah-asing@users.noreply.github.com> Date: Mon, 5 Feb 2024 09:44:23 -0800 Subject: [PATCH 1/6] bring "color" out of kwargs in bar,barh,line function signatures to match docstring --- pandas/plotting/_core.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index e8675a6d74746..cc6ddc818b0ae 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1089,7 +1089,11 @@ def __call__(self, *args, **kwargs): @Substitution(kind="line") @Appender(_bar_or_line_doc) def line( - self, x: Hashable | None = None, y: Hashable | None = None, **kwargs + self, + x: Hashable | None = None, + y: Hashable | None = None, + color: str | np.typing.ArrayLike | dict | None = None, + **kwargs, ) -> PlotAccessor: """ Plot Series or DataFrame as lines. @@ -1097,7 +1101,7 @@ def line( This function is useful to plot lines using DataFrame's values as coordinates. """ - return self(kind="line", x=x, y=y, **kwargs) + return self(kind="line", x=x, y=y, color=color, **kwargs) @Appender( """ @@ -1178,7 +1182,11 @@ def line( @Substitution(kind="bar") @Appender(_bar_or_line_doc) def bar( # pylint: disable=disallowed-name - self, x: Hashable | None = None, y: Hashable | None = None, **kwargs + self, + x: Hashable | None = None, + y: Hashable | None = None, + color: str | np.typing.ArrayLike | dict | None = None, + **kwargs, ) -> PlotAccessor: """ Vertical bar plot. @@ -1189,7 +1197,7 @@ def bar( # pylint: disable=disallowed-name axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - return self(kind="bar", x=x, y=y, **kwargs) + return self(kind="bar", x=x, y=y, color=color, **kwargs) @Appender( """ @@ -1266,7 +1274,11 @@ def bar( # pylint: disable=disallowed-name @Substitution(kind="bar") @Appender(_bar_or_line_doc) def barh( - self, x: Hashable | None = None, y: Hashable | None = None, **kwargs + self, + x: Hashable | None = None, + y: Hashable | None = None, + color: str | np.typing.ArrayLike | dict | None = None, + **kwargs, ) -> PlotAccessor: """ Make a horizontal bar plot. @@ -1277,7 +1289,7 @@ def barh( axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - return self(kind="barh", x=x, y=y, **kwargs) + return self(kind="barh", x=x, y=y, color=color, **kwargs) def box(self, by: IndexLabel | None = None, **kwargs) -> PlotAccessor: r""" From 9073b1cd43b0b321ff85877c309565c6601249ea Mon Sep 17 00:00:00 2001 From: noah-asing <7989798+noah-asing@users.noreply.github.com> Date: Mon, 5 Feb 2024 11:15:50 -0800 Subject: [PATCH 2/6] bring "y" out of kwargs in pie function signatures to match docstring --- pandas/plotting/_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index cc6ddc818b0ae..1329619959312 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1614,7 +1614,7 @@ def area( """ return self(kind="area", x=x, y=y, stacked=stacked, **kwargs) - def pie(self, **kwargs) -> PlotAccessor: + def pie(self, y: int | str | None = None, **kwargs) -> PlotAccessor: """ Generate a pie plot. @@ -1663,11 +1663,11 @@ def pie(self, **kwargs) -> PlotAccessor: """ if ( isinstance(self._parent, ABCDataFrame) - and kwargs.get("y", None) is None + and y is None and not kwargs.get("subplots", False) ): raise ValueError("pie requires either y column or 'subplots=True'") - return self(kind="pie", **kwargs) + return self(kind="pie", y=y, **kwargs) def scatter( self, From 54591b09e75fcbc3eca64923bf3dbbcf075869d0 Mon Sep 17 00:00:00 2001 From: noah-asing <7989798+noah-asing@users.noreply.github.com> Date: Mon, 5 Feb 2024 11:38:38 -0800 Subject: [PATCH 3/6] update code_checks for fixed docstrings --- ci/code_checks.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index cebc8e976425b..a23e0282ab867 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -107,15 +107,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Series.cat.remove_categories\ pandas.Series.cat.set_categories\ pandas.Series.plot\ - pandas.Series.plot.bar\ - pandas.Series.plot.barh\ - pandas.Series.plot.line\ - pandas.Series.plot.pie\ pandas.DataFrame.plot\ - pandas.DataFrame.plot.bar\ - pandas.DataFrame.plot.barh\ - pandas.DataFrame.plot.line\ - pandas.DataFrame.plot.pie\ pandas.tseries.offsets.DateOffset\ pandas.tseries.offsets.BusinessDay\ pandas.tseries.offsets.BDay\ From a22eedfbb42d0bdc60d051919e55b9b7a900c791 Mon Sep 17 00:00:00 2001 From: noah-asing <7989798+noah-asing@users.noreply.github.com> Date: Mon, 5 Feb 2024 11:54:40 -0800 Subject: [PATCH 4/6] change typehint from np Arraylike to Sequence to avoid dependence on np typing --- pandas/plotting/_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 1329619959312..83cb3e527bab1 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1092,7 +1092,7 @@ def line( self, x: Hashable | None = None, y: Hashable | None = None, - color: str | np.typing.ArrayLike | dict | None = None, + color: str | Sequence[str] | dict | None = None, **kwargs, ) -> PlotAccessor: """ @@ -1185,7 +1185,7 @@ def bar( # pylint: disable=disallowed-name self, x: Hashable | None = None, y: Hashable | None = None, - color: str | np.typing.ArrayLike | dict | None = None, + color: str | Sequence[str] | dict | None = None, **kwargs, ) -> PlotAccessor: """ @@ -1277,7 +1277,7 @@ def barh( self, x: Hashable | None = None, y: Hashable | None = None, - color: str | np.typing.ArrayLike | dict | None = None, + color: str | Sequence[str] | dict | None = None, **kwargs, ) -> PlotAccessor: """ From f7c561b3c7ca4cf7f5b86f19c7554431f9b1f906 Mon Sep 17 00:00:00 2001 From: Noah Asing <7989798+noah-asing@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:01:47 -0800 Subject: [PATCH 5/6] Use "IndexLabel" instead of generics --- pandas/plotting/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 83cb3e527bab1..d68938e2c9912 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1614,7 +1614,7 @@ def area( """ return self(kind="area", x=x, y=y, stacked=stacked, **kwargs) - def pie(self, y: int | str | None = None, **kwargs) -> PlotAccessor: + def pie(self, y: IndexLabel | None = None, **kwargs) -> PlotAccessor: """ Generate a pie plot. From 286d44c94eb4f91773145e61b5a86baa38a60978 Mon Sep 17 00:00:00 2001 From: noah-asing <7989798+noah-asing@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:31:04 -0800 Subject: [PATCH 6/6] rebundle args into kwargs before calling self to avoid "cannot use foo arg with bar arg" errors --- pandas/plotting/_core.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index d68938e2c9912..7c02ffdbafcfa 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1101,7 +1101,9 @@ def line( This function is useful to plot lines using DataFrame's values as coordinates. """ - return self(kind="line", x=x, y=y, color=color, **kwargs) + if color is not None: + kwargs["color"] = color + return self(kind="line", x=x, y=y, **kwargs) @Appender( """ @@ -1197,7 +1199,9 @@ def bar( # pylint: disable=disallowed-name axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - return self(kind="bar", x=x, y=y, color=color, **kwargs) + if color is not None: + kwargs["color"] = color + return self(kind="bar", x=x, y=y, **kwargs) @Appender( """ @@ -1289,7 +1293,9 @@ def barh( axis of the plot shows the specific categories being compared, and the other axis represents a measured value. """ - return self(kind="barh", x=x, y=y, color=color, **kwargs) + if color is not None: + kwargs["color"] = color + return self(kind="barh", x=x, y=y, **kwargs) def box(self, by: IndexLabel | None = None, **kwargs) -> PlotAccessor: r""" @@ -1661,13 +1667,15 @@ def pie(self, y: IndexLabel | None = None, **kwargs) -> PlotAccessor: >>> plot = df.plot.pie(subplots=True, figsize=(11, 6)) """ + if y is not None: + kwargs["y"] = y if ( isinstance(self._parent, ABCDataFrame) - and y is None + and kwargs.get("y", None) is None and not kwargs.get("subplots", False) ): raise ValueError("pie requires either y column or 'subplots=True'") - return self(kind="pie", y=y, **kwargs) + return self(kind="pie", **kwargs) def scatter( self,