Skip to content

Commit 71f546a

Browse files
bsun94vladu
authored andcommitted
BUG: Update Styler.clear method to clear all (pandas-dev#40664)
1 parent a1589f9 commit 71f546a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Other enhancements
161161
- :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None`` (:issue:`39359`)
162162
- :meth:`.Styler.apply` and :meth:`.Styler.applymap` now raise errors if wrong format CSS is passed on render (:issue:`39660`)
163163
- :meth:`.Styler.format` adds keyword argument ``escape`` for optional HTML escaping (:issue:`40437`)
164+
- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`)
164165
- Builtin highlighting methods in :class:`Styler` have a more consistent signature and css customisability (:issue:`40242`)
165166
- :meth:`Series.loc.__getitem__` and :meth:`Series.loc.__setitem__` with :class:`MultiIndex` now raising helpful error message when indexer has too many dimensions (:issue:`35349`)
166167
- :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files.

pandas/io/formats/style.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,12 @@ def clear(self) -> None:
881881
self.ctx.clear()
882882
self.tooltips = None
883883
self.cell_context.clear()
884-
self._todo = []
884+
self._todo.clear()
885+
886+
self.hidden_index = False
887+
self.hidden_columns = []
888+
# self.format and self.table_styles may be dependent on user
889+
# input in self.__init__()
885890

886891
def _compute(self):
887892
"""

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

+5
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,13 @@ def test_clear(self):
174174
tt = DataFrame({"A": [None, "tt"]})
175175
css = DataFrame({"A": [None, "cls-a"]})
176176
s = self.df.style.highlight_max().set_tooltips(tt).set_td_classes(css)
177+
s = s.hide_index().hide_columns("A")
177178
# _todo, tooltips and cell_context items added to..
178179
assert len(s._todo) > 0
179180
assert s.tooltips
180181
assert len(s.cell_context) > 0
182+
assert s.hidden_index is True
183+
assert len(s.hidden_columns) > 0
181184

182185
s = s._compute()
183186
# ctx item affected when a render takes place. _todo is maintained
@@ -190,6 +193,8 @@ def test_clear(self):
190193
assert len(s._todo) == 0
191194
assert not s.tooltips
192195
assert len(s.cell_context) == 0
196+
assert s.hidden_index is False
197+
assert len(s.hidden_columns) == 0
193198

194199
def test_render(self):
195200
df = DataFrame({"A": [0, 1]})

0 commit comments

Comments
 (0)