Skip to content

Commit 67b863b

Browse files
committed
add tests
1 parent 23ae4aa commit 67b863b

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

pandas/tests/io/formats/style/test_bar.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,3 @@ def test_bar_value_error_raises():
305305
msg = r"`height` must be a value in \[0, 100\]"
306306
with pytest.raises(ValueError, match=msg):
307307
df.style.bar(height=200).to_html()
308-
309-
310-
def test_bar_color_raises(df_pos):
311-
msg = "`colors` must be a matplotlib Colormap if not string"
312-
with pytest.raises(ValueError, match=msg):
313-
df_pos.style.bar(color={"a", "b"}).to_html()
314-
315-
msg = "`color` must be string, list-like of 2 strings, or matplotlib Colormap"
316-
with pytest.raises(ValueError, match=msg):
317-
df_pos.style.bar(color=["a", "b", "c"]).to_html()

pandas/tests/io/formats/style/test_matplotlib.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
pytest.importorskip("matplotlib")
1111
pytest.importorskip("jinja2")
1212

13+
import matplotlib as mpl
14+
1315
from pandas.io.formats.style import Styler
1416

1517

@@ -256,3 +258,26 @@ def test_background_gradient_gmap_wrong_series(styler_blank):
256258
gmap = Series([1, 2], index=["X", "Y"])
257259
with pytest.raises(ValueError, match=msg):
258260
styler_blank.background_gradient(gmap=gmap, axis=None)._compute()
261+
262+
263+
def test_bar_colormap():
264+
data = DataFrame([[1, 2], [3, 4]])
265+
ctx = data.style.bar(color=mpl.cm.get_cmap("PuBu"), axis=None)._compute().ctx
266+
pubu_colors = {
267+
(0, 0): "#d0d1e6",
268+
(1, 0): "#056faf",
269+
(0, 1): "#73a9cf",
270+
(1, 1): "#023858",
271+
}
272+
for k, v in pubu_colors.items():
273+
assert v in ctx[k][1][1]
274+
275+
276+
def test_bar_color_raises(df):
277+
msg = "`colors` must be a matplotlib Colormap if not string or list of strings"
278+
with pytest.raises(ValueError, match=msg):
279+
df.style.bar(color={"a", "b"}).to_html()
280+
281+
msg = "`color` must be string, list-like of 2 strings, or matplotlib Colormap"
282+
with pytest.raises(ValueError, match=msg):
283+
df.style.bar(color=["a", "b", "c"]).to_html()

0 commit comments

Comments
 (0)