Skip to content

Commit 3ef3617

Browse files
Backport PR #35664: BUG: Styler cell_ids fails on multiple renders (#35722)
Co-authored-by: attack68 <[email protected]>
1 parent a0a6549 commit 3ef3617

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

doc/source/whatsnew/v1.1.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Fixed regressions
3434
Bug fixes
3535
~~~~~~~~~
3636

37-
- Bug in ``Styler`` whereby `cell_ids` argument had no effect due to other recent changes (:issue:`35588`).
37+
- Bug in ``Styler`` whereby `cell_ids` argument had no effect due to other recent changes (:issue:`35588`) (:issue:`35663`).
3838

3939
Categorical
4040
^^^^^^^^^^^

pandas/io/formats/style.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,16 @@ def format_attr(pair):
390390
"is_visible": (c not in hidden_columns),
391391
}
392392
# only add an id if the cell has a style
393+
props = []
393394
if self.cell_ids or (r, c) in ctx:
394395
row_dict["id"] = "_".join(cs[1:])
396+
for x in ctx[r, c]:
397+
# have to handle empty styles like ['']
398+
if x.count(":"):
399+
props.append(tuple(x.split(":")))
400+
else:
401+
props.append(("", ""))
395402
row_es.append(row_dict)
396-
props = []
397-
for x in ctx[r, c]:
398-
# have to handle empty styles like ['']
399-
if x.count(":"):
400-
props.append(tuple(x.split(":")))
401-
else:
402-
props.append(("", ""))
403403
cellstyle_map[tuple(props)].append(f"row{r}_col{c}")
404404
body.append(row_es)
405405

pandas/tests/io/formats/test_style.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,11 @@ def f(a, b, styler):
16841684

16851685
def test_no_cell_ids(self):
16861686
# GH 35588
1687+
# GH 35663
16871688
df = pd.DataFrame(data=[[0]])
1688-
s = Styler(df, uuid="_", cell_ids=False).render()
1689+
styler = Styler(df, uuid="_", cell_ids=False)
1690+
styler.render()
1691+
s = styler.render() # render twice to ensure ctx is not updated
16891692
assert s.find('<td class="data row0 col0" >') != -1
16901693

16911694

0 commit comments

Comments
 (0)