From 00c9550ad089bb4997ee03f0b98ddc77128a1b65 Mon Sep 17 00:00:00 2001 From: JoseNavy <72418396+JoseNavy@users.noreply.github.com> Date: Tue, 22 Dec 2020 13:33:36 -0700 Subject: [PATCH] Backport PR #38533: BUG&TST: HTML formatting error in Styler.render() in rowspan attribute --- doc/source/whatsnew/v1.2.0.rst | 4 ++++ pandas/io/formats/style.py | 2 +- pandas/tests/io/formats/test_style.py | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) 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 '