Skip to content

Commit 13dc2e1

Browse files
committed
BUG: Styler cell_ids fails on multiple renders
1 parent 8380708 commit 13dc2e1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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)