Skip to content

Commit 13bd183

Browse files
committed
BUG: .plot modifing colors input
Closes #12039 Just added a defensive copy in `_get_standard_colors` on list-likes.
1 parent 1ae6384 commit 13bd183

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
@@ -489,7 +489,8 @@ Bug Fixes
489489
- Bug in ``DataFrame`` when masking an empty ``DataFrame`` (:issue:`11859`)
490490

491491

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

494495

495496

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)