diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index ea08a0a6fe07b..f5fa7a71e117c 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -214,7 +214,7 @@ I/O - 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`) - 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`) - 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`) -- +- :meth:`DataFrame.to_html` now raises ``TypeError`` when using an invalid type for the ``classes`` parameter instead of ``AsseertionError`` (:issue:`25608`) - - diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 66d13bf2668f9..a543b21f287ec 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -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: diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 428f1411a10a6..9cb2704f65587 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -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)