Skip to content

Commit 8de86d4

Browse files
ArtificialQualiajreback
authored andcommitted
BUG: Fix user-facing AssertionError with to_html (#25608) (#25620)
1 parent 34e8efe commit 8de86d4

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ I/O
214214
- Bug in :func:`read_json` for ``orient='table'`` when it tries to infer dtypes by default, which is not applicable as dtypes are already defined in the JSON schema (:issue:`21345`)
215215
- Bug in :func:`read_json` for ``orient='table'`` and float index, as it infers index dtype by default, which is not applicable because index dtype is already defined in the JSON schema (:issue:`25433`)
216216
- Bug in :func:`read_json` for ``orient='table'`` and string of float column names, as it makes a column name type conversion to Timestamp, which is not applicable because column names are already defined in the JSON schema (:issue:`25435`)
217-
-
217+
- :meth:`DataFrame.to_html` now raises ``TypeError`` when using an invalid type for the ``classes`` parameter instead of ``AsseertionError`` (:issue:`25608`)
218218
-
219219
-
220220

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)