Skip to content

Commit 1231ebd

Browse files
committed
Improved test coverage for Styler.bar error conditions
1 parent 3d492f1 commit 1231ebd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,23 @@ 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_and_cmap_error_raises():
311+
df = DataFrame({"A": [1, 2, 3, 4]})
312+
msg = "`color` and `cmap` cannot both be given"
313+
# Test that providing both color and cmap raises a ValueError
314+
with pytest.raises(ValueError, match=msg):
315+
df.style.bar(color='#d65f5f', cmap='viridis').to_html()
316+
317+
318+
def test_bar_invalid_color_type_error_raises():
319+
df = DataFrame({"A": [1, 2, 3, 4]})
320+
msg = r"`color` must be string or list or tuple of 2 strings,\(eg: color=\['#d65f5f', '#5fba7d'\]\)"
321+
# Test that providing an invalid color type raises a ValueError
322+
with pytest.raises(ValueError, match=msg):
323+
df.style.bar(color=123).to_html()
324+
325+
# Test that providing a color list with more than two elements raises a ValueError
326+
with pytest.raises(ValueError, match=msg):
327+
df.style.bar(color=['#d65f5f', '#5fba7d', '#abcdef']).to_html()

0 commit comments

Comments
 (0)