From d3ab49b140cab386c816921111686dbf28b29109 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 9 Mar 2021 20:28:09 +0100 Subject: [PATCH 1/5] fix regression in Styler.export/use --- pandas/io/formats/style.py | 2 +- pandas/tests/io/formats/style/test_style.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index af8c4821df755..ec09a4cc4cd89 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -855,10 +855,10 @@ def _compute(self): (application method, *args, **kwargs) """ + self.ctx.clear() r = self for func, args, kwargs in self._todo: r = func(self)(*args, **kwargs) - self._todo = [] return r def _apply( diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index b938495ca9e31..326db16a8dbb7 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -181,9 +181,8 @@ def test_clear(self): s = s._compute() # ctx and _todo items affected when a render takes place assert len(s.ctx) > 0 - assert len(s._todo) == 0 # _todo is emptied after compute. + assert len(s._todo) > 0 # _todo is maintained after compute. - s._todo = [1] s.clear() # ctx, _todo, tooltips and cell_context items all revert to null state. assert len(s.ctx) == 0 From 081a580c9df28c5319afaeaa33d033b319ec27df Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 9 Mar 2021 20:38:47 +0100 Subject: [PATCH 2/5] fix regression in Styler.export/use --- doc/source/whatsnew/v1.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index e245bf797d932..dfed7fcf82039 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -610,7 +610,7 @@ Other - Bug in :func:`pandas.api.types.infer_dtype` not recognizing Series, Index or array with a period dtype (:issue:`23553`) - 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`) - Bug in constructing a :class:`Series` from a list and a :class:`PandasDtype` (:issue:`39357`) -- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`) +- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`, :issue:`40334`) - ``inspect.getmembers(Series)`` no longer raises an ``AbstractMethodError`` (:issue:`38782`) - Bug in :meth:`Series.where` with numeric dtype and ``other = None`` not casting to ``nan`` (:issue:`39761`) - :meth:`Index.where` behavior now mirrors :meth:`Index.putmask` behavior, i.e. ``index.where(mask, other)`` matches ``index.putmask(~mask, other)`` (:issue:`39412`) From 85e4fa0cd0827c91d409f73ae8123b287100abf9 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 9 Mar 2021 20:55:40 +0100 Subject: [PATCH 3/5] fix regression in Styler.export/use --- pandas/tests/io/formats/style/test_style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 326db16a8dbb7..e7f1f71c48fa7 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -179,7 +179,7 @@ def test_clear(self): assert len(s.cell_context) > 0 s = s._compute() - # ctx and _todo items affected when a render takes place + # ctx item affected when a render takes place. _todo is maintained assert len(s.ctx) > 0 assert len(s._todo) > 0 # _todo is maintained after compute. From 6717bd836fbe3b31ae4bd6de99d86c4c8785f6c9 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 9 Mar 2021 20:58:58 +0100 Subject: [PATCH 4/5] fix regression in Styler.export/use --- pandas/tests/io/formats/style/test_style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index e7f1f71c48fa7..bd9de4c2b6358 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -181,7 +181,7 @@ def test_clear(self): s = s._compute() # ctx item affected when a render takes place. _todo is maintained assert len(s.ctx) > 0 - assert len(s._todo) > 0 # _todo is maintained after compute. + assert len(s._todo) > 0 s.clear() # ctx, _todo, tooltips and cell_context items all revert to null state. From 0a60f8da704cf0b6344b9406e0f990c9b7a669f7 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Wed, 10 Mar 2021 07:01:08 +0100 Subject: [PATCH 5/5] fix regression in Styler.export/use --- pandas/tests/io/formats/style/test_style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index bd9de4c2b6358..ca453b55eae2e 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -766,7 +766,7 @@ def test_export(self): f = lambda x: "color: red" if x > 0 else "color: blue" g = lambda x, z: f"color: {z}" if x > 0 else f"color: {z}" style1 = self.styler - style1.applymap(f).applymap(g, z="b").highlight_max() + style1.applymap(f).applymap(g, z="b").highlight_max()._compute() # = render result = style1.export() style2 = self.df.style style2.use(result)