Skip to content

Commit b8daf79

Browse files
committed
Revert "Remove test_style temporary"
This reverts commit 76f7663.
1 parent 0f0f4bc commit b8daf79

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

pandas/tests/plotting/test_style.py

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
from cycler import cycler
2+
import pytest
3+
4+
from pandas import Series
5+
6+
from pandas.plotting._matplotlib.style import get_standard_colors
7+
8+
9+
class TestGetStandardColors:
10+
@pytest.mark.parametrize(
11+
"num_colors, expected",
12+
[
13+
(3, ["red", "green", "blue"]),
14+
(5, ["red", "green", "blue", "red", "green"]),
15+
(7, ["red", "green", "blue", "red", "green", "blue", "red"]),
16+
(2, ["red", "green"]),
17+
(1, ["red"]),
18+
],
19+
)
20+
def test_default_colors_named_from_prop_cycle(self, num_colors, expected):
21+
import matplotlib as mpl
22+
23+
mpl_params = {
24+
"axes.prop_cycle": cycler(color=["red", "green", "blue"]),
25+
}
26+
with mpl.rc_context(rc=mpl_params):
27+
result = get_standard_colors(num_colors=num_colors)
28+
assert result == expected
29+
30+
@pytest.mark.parametrize(
31+
"num_colors, expected",
32+
[
33+
(1, ["b"]),
34+
(3, ["b", "g", "r"]),
35+
(4, ["b", "g", "r", "y"]),
36+
(5, ["b", "g", "r", "y", "b"]),
37+
(7, ["b", "g", "r", "y", "b", "g", "r"]),
38+
],
39+
)
40+
def test_default_colors_named_from_prop_cycle_string(self, num_colors, expected):
41+
import matplotlib as mpl
42+
43+
mpl_params = {
44+
"axes.prop_cycle": cycler(color="bgry"),
45+
}
46+
with mpl.rc_context(rc=mpl_params):
47+
result = get_standard_colors(num_colors=num_colors)
48+
assert result == expected
49+
50+
@pytest.mark.parametrize(
51+
"num_colors, expected_name",
52+
[
53+
(1, ["C0"]),
54+
(3, ["C0", "C1", "C2"]),
55+
(
56+
12,
57+
[
58+
"C0",
59+
"C1",
60+
"C2",
61+
"C3",
62+
"C4",
63+
"C5",
64+
"C6",
65+
"C7",
66+
"C8",
67+
"C9",
68+
"C0",
69+
"C1",
70+
],
71+
),
72+
],
73+
)
74+
def test_default_colors_named_undefined_prop_cycle(self, num_colors, expected_name):
75+
import matplotlib as mpl
76+
import matplotlib.colors as mcolors
77+
78+
with mpl.rc_context(rc={}):
79+
expected = [mcolors.to_hex(x) for x in expected_name]
80+
result = get_standard_colors(num_colors=num_colors)
81+
assert result == expected
82+
83+
@pytest.mark.parametrize(
84+
"num_colors, expected",
85+
[
86+
(1, ["red", "green", (0.1, 0.2, 0.3)]),
87+
(2, ["red", "green", (0.1, 0.2, 0.3)]),
88+
(3, ["red", "green", (0.1, 0.2, 0.3)]),
89+
(4, ["red", "green", (0.1, 0.2, 0.3), "red"]),
90+
],
91+
)
92+
def test_user_input_color_sequence(self, num_colors, expected):
93+
color = ["red", "green", (0.1, 0.2, 0.3)]
94+
result = get_standard_colors(color=color, num_colors=num_colors)
95+
assert result == expected
96+
97+
@pytest.mark.parametrize(
98+
"num_colors, expected",
99+
[
100+
(1, ["r", "g", "b", "k"]),
101+
(2, ["r", "g", "b", "k"]),
102+
(3, ["r", "g", "b", "k"]),
103+
(4, ["r", "g", "b", "k"]),
104+
(5, ["r", "g", "b", "k", "r"]),
105+
(6, ["r", "g", "b", "k", "r", "g"]),
106+
],
107+
)
108+
def test_user_input_color_string(self, num_colors, expected):
109+
color = "rgbk"
110+
result = get_standard_colors(color=color, num_colors=num_colors)
111+
assert result == expected
112+
113+
@pytest.mark.parametrize(
114+
"num_colors, expected",
115+
[
116+
(1, [(0.1, 0.2, 0.3)]),
117+
(2, [(0.1, 0.2, 0.3), (0.1, 0.2, 0.3)]),
118+
(3, [(0.1, 0.2, 0.3), (0.1, 0.2, 0.3), (0.1, 0.2, 0.3)]),
119+
],
120+
)
121+
def test_user_input_color_floats(self, num_colors, expected):
122+
color = (0.1, 0.2, 0.3)
123+
result = get_standard_colors(color=color, num_colors=num_colors)
124+
assert result == expected
125+
126+
@pytest.mark.parametrize(
127+
"color, num_colors, expected",
128+
[
129+
("Crimson", 1, ["Crimson"]),
130+
("DodgerBlue", 2, ["DodgerBlue", "DodgerBlue"]),
131+
("firebrick", 3, ["firebrick", "firebrick", "firebrick"]),
132+
],
133+
)
134+
def test_user_input_named_color_string(self, color, num_colors, expected):
135+
result = get_standard_colors(color=color, num_colors=num_colors)
136+
assert result == expected
137+
138+
@pytest.mark.parametrize("color", ["", [], (), Series([], dtype="object")])
139+
def test_empty_color_raises(self, color):
140+
with pytest.raises(ValueError, match="Invalid color argument"):
141+
get_standard_colors(color=color, num_colors=1)
142+
143+
@pytest.mark.parametrize(
144+
"color",
145+
[
146+
"bad_color",
147+
("red", "green", "bad_color"),
148+
(0.1,),
149+
(0.1, 0.2),
150+
(0.1, 0.2, 0.3, 0.4, 0.5), # must be either 3 or 4 floats
151+
],
152+
)
153+
def test_bad_color_raises(self, color):
154+
with pytest.raises(ValueError, match="Invalid color"):
155+
get_standard_colors(color=color, num_colors=5)

0 commit comments

Comments
 (0)