Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Bug Fixes
- Bug in reading a HDF5 table-format ``DataFrame`` created in Python 2, in Python 3 (:issue:`24925`)
- Bug in reading a JSON with ``orient='table'`` generated by :meth:`DataFrame.to_json` with ``index=False`` (:issue:`25170`)
- Bug where float indexes could have misaligned values when printing (:issue:`25061`)
-
- Bug in converting to HTML when using an invalid type for ``classes`` parameter raised ``AsseertionError`` instead of ``TypeError`` (:issue:`25608`)

**Categorical**

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def _write_table(self, indent=0):
if isinstance(self.classes, str):
self.classes = self.classes.split()
if not isinstance(self.classes, (list, tuple)):
raise AssertionError('classes must be list or tuple, not {typ}'
.format(typ=type(self.classes)))
raise TypeError('classes must be a string, list or tuple, '
'not {typ}'.format(typ=type(self.classes)))
_classes.extend(self.classes)

if self.table_id is None:
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,13 @@ def test_ignore_display_max_colwidth(method, expected, max_colwidth):
result = getattr(df, method)()
expected = expected(max_colwidth)
assert expected in result


@pytest.mark.parametrize("classes", [True, 0])
def test_to_html_invalid_classes_type(classes):
# GH 25608
df = DataFrame()
msg = "classes must be a string, list or tuple"

with pytest.raises(TypeError, match=msg):
df.to_html(classes=classes)