Skip to content

Commit 3046626

Browse files
committed
Added a check on color argument that will issue a warning.
Not sure if need to raise TypeError or issue a UserWarning if a list with more than two elements is passed.
1 parent 524a9ab commit 3046626

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pandas/formats/style.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
from pandas.types.common import is_float, is_string_like, is_list_like
2121

22+
import warnings
23+
2224
import numpy as np
2325
import pandas as pd
2426
from pandas.compat import range
@@ -971,7 +973,7 @@ def bar(self, subset=None, align='left', axis=0,
971973
If a str is passed, the color is the same for both
972974
negative and positive numbers. If 2-tuple/list is used, the
973975
first element is the color_negative and the second is the
974-
color_positive (eg: ['d65f5f', '5fba7d'])
976+
color_positive (eg: ['#d65f5f', '#5fba7d'])
975977
width: float
976978
A number between 0 or 100. The largest value will cover ``width``
977979
percent of the cell's width
@@ -992,6 +994,15 @@ def bar(self, subset=None, align='left', axis=0,
992994

993995
if not(is_list_like(color)):
994996
color = [color, color]
997+
elif len(color) == 1:
998+
color = [color[0], color[0]]
999+
elif len(color) > 2:
1000+
msg = ("Must pass `color` as string or a list-like"
1001+
" of length 2 [ `color_negative`, `color_positive`] "
1002+
"(eg: color=['#d65f5f', '#5fba7d'])\n"
1003+
"Only the first two list elements will be used here.")
1004+
warnings.warn(msg, UserWarning)
1005+
color = [color[0], color[1]]
9951006

9961007
if align == 'left':
9971008
self.apply(self._bar_left, subset=subset, axis=axis, color=color,

0 commit comments

Comments
 (0)