diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index fe80a3b5d6d0c..8aae870d50716 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -768,6 +768,10 @@ Plotting - Bug in :meth:`DataFrame.plot` and :meth:`Series.plot` was overwriting matplotlib's shared y axes behaviour when no ``sharey`` parameter was passed (:issue:`37942`) - Bug in :meth:`DataFrame.plot` was raising a ``TypeError`` with ``ExtensionDtype`` columns (:issue:`32073`) +Styler +^^^^^^ + +- Bug in :meth:`Styler.render` HTML was generated incorrectly beacause of formatting error in rowspan attribute, it now matches with w3 syntax. (:issue:`38234`) Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 4557c10927a15..6ed31f38893dc 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -389,7 +389,7 @@ def format_attr(pair): rowspan = idx_lengths.get((c, r), 0) if rowspan > 1: es["attributes"] = [ - format_attr({"key": "rowspan", "value": rowspan}) + format_attr({"key": "rowspan", "value": f'"{rowspan}"'}) ] row_es.append(es) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index 64fe8a7730ae2..0bb422658df25 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1411,7 +1411,7 @@ def test_mi_sparse(self): "display_value": "a", "is_visible": True, "type": "th", - "attributes": ["rowspan=2"], + "attributes": ['rowspan="2"'], "class": "row_heading level0 row0", "id": "level0_row0", } @@ -1740,6 +1740,15 @@ def test_colspan_w3(self): s = Styler(df, uuid="_", cell_ids=False) assert 'l0' in s.render() + def test_rowspan_w3(self): + # GH 38533 + df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]]) + s = Styler(df, uuid="_", cell_ids=False) + assert ( + 'l0' in s.render() + ) + @pytest.mark.parametrize("len_", [1, 5, 32, 33, 100]) def test_uuid_len(self, len_): # GH 36345