From f03fb15db6a8a727dcc711edf75157a2bc059c9d Mon Sep 17 00:00:00 2001 From: Daniel Isaac Date: Tue, 14 Mar 2023 22:49:22 +0530 Subject: [PATCH 1/2] Series.plot doesn't allow color=None --- pandas/plotting/_matplotlib/core.py | 1 + pandas/tests/plotting/frame/test_frame_color.py | 7 +++++++ pandas/tests/plotting/test_series.py | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 013e36a456e30..a8d8cf0f7db65 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -377,6 +377,7 @@ def _validate_color_args(self): if ( "color" in self.kwds and self.nseries == 1 + and self.kwds["color"] is not None and not is_list_like(self.kwds["color"]) ): # support series.plot(color='green') diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index a2ab72ecb690e..b9e24ff52070e 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -659,3 +659,10 @@ def test_invalid_colormap(self): msg = "(is not a valid value)|(is not a known colormap)" with pytest.raises((ValueError, KeyError), match=msg): df.plot(colormap="invalid_colormap") + + def test_dataframe_none_color(self): + # GH51953 + df = DataFrame([[1, 2, 3]]) + ax = df.plot(color=None) + expected = self._unpack_cycler(self.plt.rcParams)[:3] + self._check_colors(ax.get_lines(), linecolors=expected) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index d21c42e3eeaf9..c294e9c23882d 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -848,3 +848,10 @@ def test_timedelta_index(self, index): xlims = (3, 1) ax = Series([1, 2], index=index).plot(xlim=(xlims)) assert ax.get_xlim() == (3, 1) + + def test_series_none_color(self): + # GH51953 + series = Series([1, 2, 3]) + ax = series.plot(color=None) + expected = self._unpack_cycler(self.plt.rcParams)[:1] + self._check_colors(ax.get_lines(), linecolors=expected) From 89017dc207f04e1f7977e85f7f803268a9430d1e Mon Sep 17 00:00:00 2001 From: dannyi96 Date: Wed, 15 Mar 2023 23:30:52 +0530 Subject: [PATCH 2/2] added whatsnew --- doc/source/whatsnew/v2.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 410a324be829e..2434da4123e9c 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -195,7 +195,7 @@ Period Plotting ^^^^^^^^ -- +- Bug in :meth:`Series.plot` when invoked with ``color=None`` (:issue:`51953`) - Groupby/resample/rolling