Skip to content

BUG: Styler.apply and applymap duplicate CSS on re-render. #39395

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

Closed
attack68 opened this issue Jan 25, 2021 · 0 comments · Fixed by #39396
Closed

BUG: Styler.apply and applymap duplicate CSS on re-render. #39395

attack68 opened this issue Jan 25, 2021 · 0 comments · Fixed by #39396
Labels
Bug Styler conditional formatting using DataFrame.style
Milestone

Comments

@attack68
Copy link
Contributor

Code Sample, a copy-pastable example

df = pd.DataFrame((np.random.rand(1, 1)*100))
s = df.style\
    .applymap(lambda x: 'background-color: black;')\
    .apply(lambda x: pd.DataFrame([['color: red;']]), axis=None)
print(s.render())
print(s.ctx)
print(s.render())
print(s.ctx)

...

<style  type="text/css" >
#T_fda50_row0_col0{
            background-color:  black;
            color:  red;
        }</style>

defaultdict(<class 'list'>, {(0, 0): ['background-color: black', 'color: red']})

<style  type="text/css" >
#T_fda50_row0_col0{
            background-color:  black;
            color:  red;
            background-color:  black;
            color:  red;
        }</style>

defaultdict(<class 'list'>, {(0, 0): ['background-color: black', 'color: red', 'background-color: black', 'color: red']})

Problem description

The private _todo list is not cleared after initial execution so repeats the execution on second render.
There does not seem to be any reason any reason to maintain the _todo list after it has been done and the ctx object has been updated with necessary css-styles.

Expected Output

Same on each render.

@attack68 attack68 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2021
@simonjayhawkins simonjayhawkins added Styler conditional formatting using DataFrame.style and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2021
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Jan 25, 2021
@jreback jreback modified the milestones: Contributions Welcome, 1.3 Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants