Skip to content

Commit 3140ef1

Browse files
authored
BUG: fix regression in Styler.export/use (pandas-dev#40334)
1 parent 7b5957f commit 3140ef1

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

doc/source/whatsnew/v1.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ Other
613613
- Bug in :func:`pandas.api.types.infer_dtype` not recognizing Series, Index or array with a period dtype (:issue:`23553`)
614614
- Bug in :func:`pandas.api.types.infer_dtype` raising an error for general :class:`.ExtensionArray` objects. It will now return ``"unknown-array"`` instead of raising (:issue:`37367`)
615615
- Bug in constructing a :class:`Series` from a list and a :class:`PandasDtype` (:issue:`39357`)
616-
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`)
616+
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`, :issue:`40334`)
617617
- ``inspect.getmembers(Series)`` no longer raises an ``AbstractMethodError`` (:issue:`38782`)
618618
- Bug in :meth:`Series.where` with numeric dtype and ``other = None`` not casting to ``nan`` (:issue:`39761`)
619619
- :meth:`Index.where` behavior now mirrors :meth:`Index.putmask` behavior, i.e. ``index.where(mask, other)`` matches ``index.putmask(~mask, other)`` (:issue:`39412`)

pandas/io/formats/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,10 @@ def _compute(self):
855855
856856
(application method, *args, **kwargs)
857857
"""
858+
self.ctx.clear()
858859
r = self
859860
for func, args, kwargs in self._todo:
860861
r = func(self)(*args, **kwargs)
861-
self._todo = []
862862
return r
863863

864864
def _apply(

pandas/tests/io/formats/style/test_style.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,10 @@ def test_clear(self):
179179
assert len(s.cell_context) > 0
180180

181181
s = s._compute()
182-
# ctx and _todo items affected when a render takes place
182+
# ctx item affected when a render takes place. _todo is maintained
183183
assert len(s.ctx) > 0
184-
assert len(s._todo) == 0 # _todo is emptied after compute.
184+
assert len(s._todo) > 0
185185

186-
s._todo = [1]
187186
s.clear()
188187
# ctx, _todo, tooltips and cell_context items all revert to null state.
189188
assert len(s.ctx) == 0
@@ -767,7 +766,7 @@ def test_export(self):
767766
f = lambda x: "color: red" if x > 0 else "color: blue"
768767
g = lambda x, z: f"color: {z}" if x > 0 else f"color: {z}"
769768
style1 = self.styler
770-
style1.applymap(f).applymap(g, z="b").highlight_max()
769+
style1.applymap(f).applymap(g, z="b").highlight_max()._compute() # = render
771770
result = style1.export()
772771
style2 = self.df.style
773772
style2.use(result)

0 commit comments

Comments
 (0)