Skip to content

Commit d7165ef

Browse files
BUG: Fix user-facing AssertionError with to_html (pandas-dev#25608)
1 parent cc4a7e5 commit d7165ef

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

doc/source/whatsnew/v0.24.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Bug Fixes
6464
- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 (:issue:`24925`)
6565
- Bug in reading a JSON with ``orient='table'`` generated by :meth:`DataFrame.to_json` with ``index=False`` (:issue:`25170`)
6666
- Bug where float indexes could have misaligned values when printing (:issue:`25061`)
67-
-
67+
- Bug in converting to HTML when using an invalid type for ``classes`` parameter raised ``AsseertionError`` instead of ``TypeError`` (:issue:`25608`)
6868

6969
**Categorical**
7070

pandas/io/formats/html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def _write_table(self, indent=0):
163163
if isinstance(self.classes, str):
164164
self.classes = self.classes.split()
165165
if not isinstance(self.classes, (list, tuple)):
166-
raise AssertionError('classes must be list or tuple, not {typ}'
167-
.format(typ=type(self.classes)))
166+
raise TypeError('classes must be a string, list or tuple, '
167+
'not {typ}'.format(typ=type(self.classes)))
168168
_classes.extend(self.classes)
169169

170170
if self.table_id is None:

pandas/tests/io/formats/test_to_html.py

+10
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,13 @@ def test_ignore_display_max_colwidth(method, expected, max_colwidth):
623623
result = getattr(df, method)()
624624
expected = expected(max_colwidth)
625625
assert expected in result
626+
627+
628+
@pytest.mark.parametrize("classes", [True, 0])
629+
def test_to_html_invalid_classes_type(classes):
630+
# GH 25608
631+
df = DataFrame()
632+
msg = "classes must be a string, list or tuple"
633+
634+
with pytest.raises(TypeError, match=msg):
635+
df.to_html(classes=classes)

0 commit comments

Comments
 (0)