19
19
20
20
from pandas .types .common import is_float , is_string_like , is_list_like
21
21
22
+ import warnings
23
+
22
24
import numpy as np
23
25
import pandas as pd
24
26
from pandas .compat import range
@@ -977,7 +979,7 @@ def bar(self, subset=None, align='left', axis=0,
977
979
If a str is passed, the color is the same for both
978
980
negative and positive numbers. If 2-tuple/list is used, the
979
981
first element is the color_negative and the second is the
980
- color_positive (eg: ['d65f5f', '5fba7d'])
982
+ color_positive (eg: ['# d65f5f', '# 5fba7d'])
981
983
width: float
982
984
A number between 0 or 100. The largest value will cover ``width``
983
985
percent of the cell's width
@@ -998,6 +1000,15 @@ def bar(self, subset=None, align='left', axis=0,
998
1000
999
1001
if not (is_list_like (color )):
1000
1002
color = [color , color ]
1003
+ elif len (color ) == 1 :
1004
+ color = [color [0 ], color [0 ]]
1005
+ elif len (color ) > 2 :
1006
+ msg = ("Must pass `color` as string or a list-like"
1007
+ " of length 2 [ `color_negative`, `color_positive`] "
1008
+ "(eg: color=['#d65f5f', '#5fba7d'])\n "
1009
+ "Only the first two list elements will be used here." )
1010
+ warnings .warn (msg , UserWarning )
1011
+ color = [color [0 ], color [1 ]]
1001
1012
1002
1013
if align == 'left' :
1003
1014
self .apply (self ._bar_left , subset = subset , axis = axis , color = color ,
0 commit comments