Skip to content

Commit

Permalink
Backport PR #38533: BUG&TST: HTML formatting error in Styler.render()…
Browse files Browse the repository at this point in the history
… in rowspan attribute (#38640)

Co-authored-by: JoseNavy <72418396+JoseNavy@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and JoseNavy committed Dec 22, 2020
1 parent 261d5a5 commit fd9670e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v1.2.0.rst
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style.py
Expand Up @@ -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)

Expand Down
11 changes: 10 additions & 1 deletion pandas/tests/io/formats/test_style.py
Expand Up @@ -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",
}
Expand Down Expand Up @@ -1740,6 +1740,15 @@ def test_colspan_w3(self):
s = Styler(df, uuid="_", cell_ids=False)
assert '<th class="col_heading level0 col0" colspan="2">l0</th>' 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 (
'<th id="T___level0_row0" class="row_heading '
'level0 row0" rowspan="2">l0</th>' in s.render()
)

@pytest.mark.parametrize("len_", [1, 5, 32, 33, 100])
def test_uuid_len(self, len_):
# GH 36345
Expand Down

0 comments on commit fd9670e

Please sign in to comment.