1919
2020from pandas .types .common import is_float , is_string_like , is_list_like
2121
22+ import warnings
23+
2224import numpy as np
2325import pandas as pd
2426from pandas .compat import range
@@ -977,7 +979,7 @@ def bar(self, subset=None, align='left', axis=0,
977979 If a str is passed, the color is the same for both
978980 negative and positive numbers. If 2-tuple/list is used, the
979981 first element is the color_negative and the second is the
980- color_positive (eg: ['d65f5f', '5fba7d'])
982+ color_positive (eg: ['# d65f5f', '# 5fba7d'])
981983 width: float
982984 A number between 0 or 100. The largest value will cover ``width``
983985 percent of the cell's width
@@ -998,6 +1000,15 @@ def bar(self, subset=None, align='left', axis=0,
9981000
9991001 if not (is_list_like (color )):
10001002 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 ]]
10011012
10021013 if align == 'left' :
10031014 self .apply (self ._bar_left , subset = subset , axis = axis , color = color ,
0 commit comments