From 00b7b8860a4d3a78b01cd80f9e6f05ce868904b2 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 5 Nov 2019 13:11:52 -0500 Subject: [PATCH 1/4] test, fixup --- pandas/plotting/_matplotlib/core.py | 4 +++- pandas/tests/plotting/test_series.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 541dca715e814..49eb96f2053ef 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -193,6 +193,8 @@ def __init__( self._validate_color_args() def _validate_color_args(self): + import matplotlib.colors + if "color" not in self.kwds and "colors" in self.kwds: warnings.warn( ( @@ -234,7 +236,7 @@ def _validate_color_args(self): styles = [self.style] # need only a single match for s in styles: - if re.match("^[a-z]+?", s) is not None: + if s in matplotlib.colors.BASE_COLORS: raise ValueError( "Cannot pass 'style' string with a color " "symbol and 'color' keyword argument. Please" diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 89259cbb6c62d..2ecde4fed92cd 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -931,3 +931,7 @@ def test_plot_no_numeric_data(self): df = pd.Series(["a", "b", "c"]) with pytest.raises(TypeError): df.plot() + + def test_style_single_ok(self): + s = pd.Series([1, 2]) + s.plot(style="s", color="C3") From 914b7b980f8be4f78291958cfeaa5d9d3425b62e Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 5 Nov 2019 13:23:05 -0500 Subject: [PATCH 2/4] whatsnew --- doc/source/whatsnew/v1.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index b40a64420a0be..7effb7d4c7a12 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -410,6 +410,7 @@ Plotting - Bug in the ``xticks`` argument being ignored for :meth:`DataFrame.plot.bar` (:issue:`14119`) - :func:`set_option` now validates that the plot backend provided to ``'plotting.backend'`` implements the backend when the option is set, rather than when a plot is created (:issue:`28163`) - :meth:`DataFrame.plot` now allow a ``backend`` keyword arugment to allow changing between backends in one session (:issue:`28619`). +- Bug in color validation incorrectly raising for non-color styles :issue:`29122`). Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ From c9a0e4c731990a8ebdf62e066d9d655b15fdf9f3 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 5 Nov 2019 13:23:53 -0500 Subject: [PATCH 3/4] paran --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 7effb7d4c7a12..29a562aa1a1f2 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -410,7 +410,7 @@ Plotting - Bug in the ``xticks`` argument being ignored for :meth:`DataFrame.plot.bar` (:issue:`14119`) - :func:`set_option` now validates that the plot backend provided to ``'plotting.backend'`` implements the backend when the option is set, rather than when a plot is created (:issue:`28163`) - :meth:`DataFrame.plot` now allow a ``backend`` keyword arugment to allow changing between backends in one session (:issue:`28619`). -- Bug in color validation incorrectly raising for non-color styles :issue:`29122`). +- Bug in color validation incorrectly raising for non-color styles (:issue:`29122`). Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ From 563481ebd1fee4bcb3268bf4bc086db141e27f4e Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 5 Nov 2019 17:00:37 -0500 Subject: [PATCH 4/4] test, fix --- pandas/plotting/_matplotlib/core.py | 15 ++++++++------- pandas/tests/plotting/test_series.py | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 49eb96f2053ef..5853367f71d56 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -236,13 +236,14 @@ def _validate_color_args(self): styles = [self.style] # need only a single match for s in styles: - if s in matplotlib.colors.BASE_COLORS: - raise ValueError( - "Cannot pass 'style' string with a color " - "symbol and 'color' keyword argument. Please" - " use one or the other or pass 'style' " - "without a color symbol" - ) + for char in s: + if char in matplotlib.colors.BASE_COLORS: + raise ValueError( + "Cannot pass 'style' string with a color " + "symbol and 'color' keyword argument. Please" + " use one or the other or pass 'style' " + "without a color symbol" + ) def _iter_data(self, data=None, keep_index=False, fillna=None): if data is None: diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 2ecde4fed92cd..766b1f61e9c1b 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -934,4 +934,5 @@ def test_plot_no_numeric_data(self): def test_style_single_ok(self): s = pd.Series([1, 2]) - s.plot(style="s", color="C3") + ax = s.plot(style="s", color="C3") + assert ax.lines[0].get_color() == ["C3"]