Skip to content

Commit 81c9e38

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 d78dd70 commit 81c9e38

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
@@ -966,7 +968,7 @@ def bar(self, subset=None, align='left', axis=0,
966968
If a str is passed, the color is the same for both
967969
negative and positive numbers. If 2-tuple/list is used, the
968970
first element is the color_negative and the second is the
969-
color_positive (eg: ['d65f5f', '5fba7d'])
971+
color_positive (eg: ['#d65f5f', '#5fba7d'])
970972
width: float
971973
A number between 0 or 100. The largest value will cover ``width``
972974
percent of the cell's width
@@ -987,6 +989,15 @@ def bar(self, subset=None, align='left', axis=0,
987989

988990
if not(is_list_like(color)):
989991
color = [color, color]
992+
elif len(color) == 1:
993+
color = [color[0], color[0]]
994+
elif len(color) > 2:
995+
msg = ("Must pass `color` as string or a list-like"
996+
" of length 2 [ `color_negative`, `color_positive`] "
997+
"(eg: color=['#d65f5f', '#5fba7d'])\n"
998+
"Only the first two list elements will be used here.")
999+
warnings.warn(msg, UserWarning)
1000+
color = [color[0], color[1]]
9901001

9911002
if align == 'left':
9921003
self.apply(self._bar_left, subset=subset, axis=axis, color=color,

0 commit comments

Comments
 (0)