Skip to content

BUG: Styler cell_ids fails on multiple renders #35664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Fixed regressions
Bug fixes
~~~~~~~~~

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

Categorical
^^^^^^^^^^^
Expand Down
14 changes: 7 additions & 7 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,16 @@ def format_attr(pair):
"is_visible": (c not in hidden_columns),
}
# only add an id if the cell has a style
props = []
if self.cell_ids or (r, c) in ctx:
row_dict["id"] = "_".join(cs[1:])
for x in ctx[r, c]:
# have to handle empty styles like ['']
if x.count(":"):
props.append(tuple(x.split(":")))
else:
props.append(("", ""))
row_es.append(row_dict)
props = []
for x in ctx[r, c]:
# have to handle empty styles like ['']
if x.count(":"):
props.append(tuple(x.split(":")))
else:
props.append(("", ""))
cellstyle_map[tuple(props)].append(f"row{r}_col{c}")
body.append(row_es)

Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/io/formats/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,11 @@ def f(a, b, styler):

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


Expand Down