-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: re-render CSS with styler.apply
and applymap
non-cleared _todo
#39396
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,12 +102,24 @@ def test_deepcopy(self): | |
assert self.styler._todo != s2._todo | ||
|
||
def test_clear(self): | ||
s = self.df.style.highlight_max()._compute() | ||
assert len(s.ctx) > 0 | ||
tt = DataFrame({"A": [None, "tt"]}) | ||
css = DataFrame({"A": [None, "cls-a"]}) | ||
s = self.df.style.highlight_max().set_tooltips(tt).set_td_classes(css) | ||
# _todo, tooltips and cell_context items all affected.. | ||
assert len(s._todo) > 0 | ||
assert s.tooltips | ||
assert len(s.cell_context) > 0 | ||
s = s._compute() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason we are calling private methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is legacy from my perspective. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, yeah i fyou can just add some blank lines here so its a bit more obvious what is tested |
||
# ctx and _todo items affected | ||
assert len(s.ctx) > 0 | ||
assert len(s._todo) == 0 # _todo is emptied after compute. | ||
s._todo = [1] | ||
s.clear() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a line break / comment here |
||
# ctx, _todo, tooltips and cell_context items all revert to null state. | ||
assert len(s.ctx) == 0 | ||
assert len(s._todo) == 0 | ||
assert not s.tooltips | ||
assert len(s.cell_context) == 0 | ||
|
||
def test_render(self): | ||
df = DataFrame({"A": [0, 1]}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we not just call
.clear()
first?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
_compute
method deals only with the_todo
list which is the composition of usersapply
andapplymap
methods. It populates thectx
object which is later used by_translate
to render the HTML.the
clear
method removes the_todo
list as well as other objects such asTooltips
, thectx
object and thecell_context
object from theStyler
. You don't want to remove all these at this stage. I think you just want to empty the_todo
list after its been 'done'.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everytime a
Styler
is displayed in JupyterNotebook cell it callsrender()
and the css is processed (duplicated in the current version). Since HTML just reads the most recent CSS, duplicate CSS doesn't affect the display to user, but for debugging or network transferring the HTML it is best obviously to only generate the css once.A common user pattern might be to build up styles in notebooks consecutively, meaning multiple cell renders will affect the html output.
Consider 3 cells, so ultimately 3 renders:
This PR reduces the final output, without any other implications, to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok can you add a test that replicates this