From 13bd183dd350403483c9698141c76b6cf791d981 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 14 Jan 2016 20:56:08 -0600 Subject: [PATCH] BUG: .plot modifing `colors` input Closes https://github.com/pydata/pandas/issues/12039 Just added a defensive copy in `_get_standard_colors` on list-likes. --- doc/source/whatsnew/v0.18.0.txt | 3 ++- pandas/tests/test_graphics.py | 6 ++++++ pandas/tools/plotting.py | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index 4ce2ce5b69cb4..9effa186017fd 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -489,7 +489,8 @@ Bug Fixes - Bug in ``DataFrame`` when masking an empty ``DataFrame`` (:issue:`11859`) - +- Bug in ``.plot`` potentially modifying the ``colors`` input when the number +of columns didn't match the number of series provided (:issue:`12039`). diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index ff69068a3495c..0fc5916676dd3 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -2717,6 +2717,12 @@ def test_line_colors(self): # Forced show plot _check_plot_works(df.plot, color=custom_colors) + @slow + def test_dont_modify_colors(self): + colors = ['r', 'g', 'b'] + pd.DataFrame(np.random.rand(10, 2)).plot(color=colors) + self.assertEqual(len(colors), 3) + @slow def test_line_colors_and_styles_subplots(self): # GH 9894 diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 3e9c788914a5a..43bcd2373df69 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -158,7 +158,7 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default', if colormap is not None: warnings.warn("'color' and 'colormap' cannot be used " "simultaneously. Using 'color'") - colors = color + colors = list(color) if com.is_list_like(color) else color else: if color_type == 'default': # need to call list() on the result to copy so we don't