Skip to content

Commit 80a3ce0

Browse files
committed
Check for bad align value and raise. Wrote test for it too
1 parent 5875eb9 commit 80a3ce0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/formats/style.py

+4
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ def bar(self, subset=None, align='left', axis=0,
10291029
elif align == 'mid':
10301030
self.apply(self._bar_center_mid, subset=subset, axis=axis,
10311031
color=color, width=width, base=base)
1032+
else:
1033+
msg = ("`align` must be one of {'left', 'zero',' mid'}")
1034+
raise ValueError(msg)
1035+
10321036
return self
10331037

10341038
def highlight_max(self, subset=None, color='yellow', axis=0):

pandas/tests/formats/test_style.py

+5
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ def test_bar_align_mid_all_neg(self):
452452
'#d65f5f 80.0%, #d65f5f 100.0%, transparent 100.0%)']}
453453
self.assertEqual(result, expected)
454454

455+
def test_bar_bad_align_raises(self):
456+
df = pd.DataFrame({'A': [-100, -60, -30, -20]})
457+
with tm.assertRaises(ValueError):
458+
df.style.bar(align='poorly', color=['#d65f5f', '#5fba7d'])
459+
455460
def test_highlight_null(self, null_color='red'):
456461
df = pd.DataFrame({'A': [0, np.nan]})
457462
result = df.style.highlight_null()._compute().ctx

0 commit comments

Comments
 (0)