@@ -305,3 +305,23 @@ def test_bar_value_error_raises():
305
305
msg = r"`height` must be a value in \[0, 100\]"
306
306
with pytest .raises (ValueError , match = msg ):
307
307
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