Skip to content

Commit fd9670e

Browse files
Backport PR #38533: BUG&TST: HTML formatting error in Styler.render() in rowspan attribute (#38640)
Co-authored-by: JoseNavy <[email protected]>
1 parent 261d5a5 commit fd9670e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v1.2.0.rst

+4
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ Plotting
768768
- 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`)
769769
- Bug in :meth:`DataFrame.plot` was raising a ``TypeError`` with ``ExtensionDtype`` columns (:issue:`32073`)
770770

771+
Styler
772+
^^^^^^
773+
774+
- Bug in :meth:`Styler.render` HTML was generated incorrectly beacause of formatting error in rowspan attribute, it now matches with w3 syntax. (:issue:`38234`)
771775

772776
Groupby/resample/rolling
773777
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/io/formats/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def format_attr(pair):
389389
rowspan = idx_lengths.get((c, r), 0)
390390
if rowspan > 1:
391391
es["attributes"] = [
392-
format_attr({"key": "rowspan", "value": rowspan})
392+
format_attr({"key": "rowspan", "value": f'"{rowspan}"'})
393393
]
394394
row_es.append(es)
395395

pandas/tests/io/formats/test_style.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ def test_mi_sparse(self):
14111411
"display_value": "a",
14121412
"is_visible": True,
14131413
"type": "th",
1414-
"attributes": ["rowspan=2"],
1414+
"attributes": ['rowspan="2"'],
14151415
"class": "row_heading level0 row0",
14161416
"id": "level0_row0",
14171417
}
@@ -1740,6 +1740,15 @@ def test_colspan_w3(self):
17401740
s = Styler(df, uuid="_", cell_ids=False)
17411741
assert '<th class="col_heading level0 col0" colspan="2">l0</th>' in s.render()
17421742

1743+
def test_rowspan_w3(self):
1744+
# GH 38533
1745+
df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]])
1746+
s = Styler(df, uuid="_", cell_ids=False)
1747+
assert (
1748+
'<th id="T___level0_row0" class="row_heading '
1749+
'level0 row0" rowspan="2">l0</th>' in s.render()
1750+
)
1751+
17431752
@pytest.mark.parametrize("len_", [1, 5, 32, 33, 100])
17441753
def test_uuid_len(self, len_):
17451754
# GH 36345

0 commit comments

Comments
 (0)