Skip to content

DOC: fix pr02 errors in docstrings - plot.bar, plot.barh, plot.line, plot.pie #57266

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 8 commits into from
Feb 7, 2024
8 changes: 0 additions & 8 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,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\
Expand Down
28 changes: 24 additions & 4 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,14 +1089,20 @@ 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 | Sequence[str] | dict | None = None,
**kwargs,
) -> PlotAccessor:
"""
Plot Series or DataFrame as lines.

This function is useful to plot lines using DataFrame's values
as coordinates.
"""
if color is not None:
Copy link
Member

Choose a reason for hiding this comment

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

Instead can you just specify return self(..., color=color, **kwargs)? (and likewise below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be prettier, but calling self(..., color=None, colormap=foo) raises UserWarnings for simultaneous usage of conflicting args, and the function defaults to use color=None, ignoring the value of colormap.

Similar situation for y in the pieplot, which conflicts with the usage of subplots depending on their respective values.

kwargs["color"] = color
return self(kind="line", x=x, y=y, **kwargs)

@Appender(
Expand Down Expand Up @@ -1178,7 +1184,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 | Sequence[str] | dict | None = None,
**kwargs,
) -> PlotAccessor:
"""
Vertical bar plot.
Expand All @@ -1189,6 +1199,8 @@ def bar( # pylint: disable=disallowed-name
axis of the plot shows the specific categories being compared, and the
other axis represents a measured value.
"""
if color is not None:
kwargs["color"] = color
return self(kind="bar", x=x, y=y, **kwargs)

@Appender(
Expand Down Expand Up @@ -1266,7 +1278,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 | Sequence[str] | dict | None = None,
**kwargs,
) -> PlotAccessor:
"""
Make a horizontal bar plot.
Expand All @@ -1277,6 +1293,8 @@ def barh(
axis of the plot shows the specific categories being compared, and the
other axis represents a measured value.
"""
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:
Expand Down Expand Up @@ -1602,7 +1620,7 @@ def area(
"""
return self(kind="area", x=x, y=y, stacked=stacked, **kwargs)

def pie(self, **kwargs) -> PlotAccessor:
def pie(self, y: IndexLabel | None = None, **kwargs) -> PlotAccessor:
"""
Generate a pie plot.

Expand Down Expand Up @@ -1649,6 +1667,8 @@ def pie(self, **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 kwargs.get("y", None) is None
Expand Down