Skip to content

Make color validation more forgiving #29122

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 4 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")