peacock-data-public-datasets-idc-cronscript
/
venv
/lib
/python3.10
/site-packages
/pandas
/tests
/plotting
/test_style.py
import pytest | |
from pandas import Series | |
pytest.importorskip("matplotlib") | |
from pandas.plotting._matplotlib.style import get_standard_colors | |
class TestGetStandardColors: | |
def test_default_colors_named_from_prop_cycle(self, num_colors, expected): | |
import matplotlib as mpl | |
from matplotlib.pyplot import cycler | |
mpl_params = { | |
"axes.prop_cycle": cycler(color=["red", "green", "blue"]), | |
} | |
with mpl.rc_context(rc=mpl_params): | |
result = get_standard_colors(num_colors=num_colors) | |
assert result == expected | |
def test_default_colors_named_from_prop_cycle_string(self, num_colors, expected): | |
import matplotlib as mpl | |
from matplotlib.pyplot import cycler | |
mpl_params = { | |
"axes.prop_cycle": cycler(color="bgry"), | |
} | |
with mpl.rc_context(rc=mpl_params): | |
result = get_standard_colors(num_colors=num_colors) | |
assert result == expected | |
def test_default_colors_named_undefined_prop_cycle(self, num_colors, expected_name): | |
import matplotlib as mpl | |
import matplotlib.colors as mcolors | |
with mpl.rc_context(rc={}): | |
expected = [mcolors.to_hex(x) for x in expected_name] | |
result = get_standard_colors(num_colors=num_colors) | |
assert result == expected | |
def test_user_input_color_sequence(self, num_colors, expected): | |
color = ["red", "green", (0.1, 0.2, 0.3)] | |
result = get_standard_colors(color=color, num_colors=num_colors) | |
assert result == expected | |
def test_user_input_color_string(self, num_colors, expected): | |
color = "rgbk" | |
result = get_standard_colors(color=color, num_colors=num_colors) | |
assert result == expected | |
def test_user_input_color_floats(self, num_colors, expected): | |
color = (0.1, 0.2, 0.3) | |
result = get_standard_colors(color=color, num_colors=num_colors) | |
assert result == expected | |
def test_user_input_named_color_string(self, color, num_colors, expected): | |
result = get_standard_colors(color=color, num_colors=num_colors) | |
assert result == expected | |
def test_empty_color_raises(self, color): | |
with pytest.raises(ValueError, match="Invalid color argument"): | |
get_standard_colors(color=color, num_colors=1) | |
def test_bad_color_raises(self, color): | |
with pytest.raises(ValueError, match="Invalid color"): | |
get_standard_colors(color=color, num_colors=5) | |