Skip to content

BUG: Ensuring that _get_standard_colors returns num_colors (GH #20585) #24504

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 10 commits into from
Jan 2, 2019
2 changes: 2 additions & 0 deletions pandas/plotting/_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
list('bgrcmyk')))
if isinstance(colors, compat.string_types):
colors = list(colors)

colors = colors[0:num_colors]
elif color_type == 'random':
import pandas.core.common as com

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,13 @@ def test_get_standard_colors_random_seed(self):
color1 = _get_standard_colors(1, color_type='random')
color2 = _get_standard_colors(1, color_type='random')
assert color1 == color2

def test_get_standard_colors_default_num_colors(self):
from pandas.plotting._style import _get_standard_colors

color1 = _get_standard_colors(1, color_type='default')
color2 = _get_standard_colors(9, color_type='default')
color3 = _get_standard_colors(20, color_type='default')
assert len(color1) == 1
assert len(color2) == 9
assert len(color3) == 20