Skip to content

Commit 02d1c30

Browse files
author
Tom Augspurger
committed
Merge pull request pandas-dev#12040 from TomAugspurger/modify-color
BUG: .plot modifing `colors` input
2 parents 3a832df + 13bd183 commit 02d1c30

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/whatsnew/v0.18.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ Bug Fixes
493493
- Bug in ``DataFrame`` when masking an empty ``DataFrame`` (:issue:`11859`)
494494

495495

496-
496+
- Bug in ``.plot`` potentially modifying the ``colors`` input when the number
497+
of columns didn't match the number of series provided (:issue:`12039`).
497498

498499

499500

pandas/tests/test_graphics.py

+6
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,12 @@ def test_line_colors(self):
27172717
# Forced show plot
27182718
_check_plot_works(df.plot, color=custom_colors)
27192719

2720+
@slow
2721+
def test_dont_modify_colors(self):
2722+
colors = ['r', 'g', 'b']
2723+
pd.DataFrame(np.random.rand(10, 2)).plot(color=colors)
2724+
self.assertEqual(len(colors), 3)
2725+
27202726
@slow
27212727
def test_line_colors_and_styles_subplots(self):
27222728
# GH 9894

pandas/tools/plotting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
158158
if colormap is not None:
159159
warnings.warn("'color' and 'colormap' cannot be used "
160160
"simultaneously. Using 'color'")
161-
colors = color
161+
colors = list(color) if com.is_list_like(color) else color
162162
else:
163163
if color_type == 'default':
164164
# need to call list() on the result to copy so we don't

0 commit comments

Comments
 (0)