Skip to content

Commit 65b267a

Browse files
authored
DOC: fix pr02 errors in docstrings - plot.bar, plot.barh, plot.line, plot.pie (pandas-dev#57266)
* bring "color" out of kwargs in bar,barh,line function signatures to match docstring * bring "y" out of kwargs in pie function signatures to match docstring * update code_checks for fixed docstrings * change typehint from np Arraylike to Sequence to avoid dependence on np typing * Use "IndexLabel" instead of generics * rebundle args into kwargs before calling self to avoid "cannot use foo arg with bar arg" errors
1 parent 7a3f80f commit 65b267a

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

ci/code_checks.sh

-8
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8787
pandas.Series.cat.remove_categories\
8888
pandas.Series.cat.set_categories\
8989
pandas.Series.plot\
90-
pandas.Series.plot.bar\
91-
pandas.Series.plot.barh\
92-
pandas.Series.plot.line\
93-
pandas.Series.plot.pie\
9490
pandas.DataFrame.plot\
95-
pandas.DataFrame.plot.bar\
96-
pandas.DataFrame.plot.barh\
97-
pandas.DataFrame.plot.line\
98-
pandas.DataFrame.plot.pie\
9991
pandas.tseries.offsets.DateOffset\
10092
pandas.tseries.offsets.BusinessDay\
10193
pandas.tseries.offsets.BDay\

pandas/plotting/_core.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -1089,14 +1089,20 @@ def __call__(self, *args, **kwargs):
10891089
@Substitution(kind="line")
10901090
@Appender(_bar_or_line_doc)
10911091
def line(
1092-
self, x: Hashable | None = None, y: Hashable | None = None, **kwargs
1092+
self,
1093+
x: Hashable | None = None,
1094+
y: Hashable | None = None,
1095+
color: str | Sequence[str] | dict | None = None,
1096+
**kwargs,
10931097
) -> PlotAccessor:
10941098
"""
10951099
Plot Series or DataFrame as lines.
10961100
10971101
This function is useful to plot lines using DataFrame's values
10981102
as coordinates.
10991103
"""
1104+
if color is not None:
1105+
kwargs["color"] = color
11001106
return self(kind="line", x=x, y=y, **kwargs)
11011107

11021108
@Appender(
@@ -1178,7 +1184,11 @@ def line(
11781184
@Substitution(kind="bar")
11791185
@Appender(_bar_or_line_doc)
11801186
def bar( # pylint: disable=disallowed-name
1181-
self, x: Hashable | None = None, y: Hashable | None = None, **kwargs
1187+
self,
1188+
x: Hashable | None = None,
1189+
y: Hashable | None = None,
1190+
color: str | Sequence[str] | dict | None = None,
1191+
**kwargs,
11821192
) -> PlotAccessor:
11831193
"""
11841194
Vertical bar plot.
@@ -1189,6 +1199,8 @@ def bar( # pylint: disable=disallowed-name
11891199
axis of the plot shows the specific categories being compared, and the
11901200
other axis represents a measured value.
11911201
"""
1202+
if color is not None:
1203+
kwargs["color"] = color
11921204
return self(kind="bar", x=x, y=y, **kwargs)
11931205

11941206
@Appender(
@@ -1266,7 +1278,11 @@ def bar( # pylint: disable=disallowed-name
12661278
@Substitution(kind="bar")
12671279
@Appender(_bar_or_line_doc)
12681280
def barh(
1269-
self, x: Hashable | None = None, y: Hashable | None = None, **kwargs
1281+
self,
1282+
x: Hashable | None = None,
1283+
y: Hashable | None = None,
1284+
color: str | Sequence[str] | dict | None = None,
1285+
**kwargs,
12701286
) -> PlotAccessor:
12711287
"""
12721288
Make a horizontal bar plot.
@@ -1277,6 +1293,8 @@ def barh(
12771293
axis of the plot shows the specific categories being compared, and the
12781294
other axis represents a measured value.
12791295
"""
1296+
if color is not None:
1297+
kwargs["color"] = color
12801298
return self(kind="barh", x=x, y=y, **kwargs)
12811299

12821300
def box(self, by: IndexLabel | None = None, **kwargs) -> PlotAccessor:
@@ -1602,7 +1620,7 @@ def area(
16021620
"""
16031621
return self(kind="area", x=x, y=y, stacked=stacked, **kwargs)
16041622

1605-
def pie(self, **kwargs) -> PlotAccessor:
1623+
def pie(self, y: IndexLabel | None = None, **kwargs) -> PlotAccessor:
16061624
"""
16071625
Generate a pie plot.
16081626
@@ -1649,6 +1667,8 @@ def pie(self, **kwargs) -> PlotAccessor:
16491667
16501668
>>> plot = df.plot.pie(subplots=True, figsize=(11, 6))
16511669
"""
1670+
if y is not None:
1671+
kwargs["y"] = y
16521672
if (
16531673
isinstance(self._parent, ABCDataFrame)
16541674
and kwargs.get("y", None) is None

0 commit comments

Comments
 (0)