diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 92efb225682b7..78fb8838a9fa9 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -137,6 +137,7 @@ Other enhancements - :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None`` (:issue:`39359`) - :meth:`.Styler.apply` and :meth:`.Styler.applymap` now raise errors if wrong format CSS is passed on render (:issue:`39660`) - :meth:`.Styler.format` adds keyword argument ``escape`` for optional HTML escaping (:issue:`40437`) +- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`) - Builtin highlighting methods in :class:`Styler` have a more consistent signature and css customisability (:issue:`40242`) - :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`) - :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files. diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 9250d861740fc..daab955cf1fbe 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -882,7 +882,12 @@ def clear(self) -> None: self.ctx.clear() self.tooltips = None self.cell_context.clear() - self._todo = [] + self._todo.clear() + + self.hidden_index = False + self.hidden_columns = [] + # self.format and self.table_styles may be dependent on user + # input in self.__init__() def _compute(self): """ diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 302019b702829..3422eb9dc64b7 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -174,10 +174,13 @@ def test_clear(self): tt = DataFrame({"A": [None, "tt"]}) css = DataFrame({"A": [None, "cls-a"]}) s = self.df.style.highlight_max().set_tooltips(tt).set_td_classes(css) + s = s.hide_index().hide_columns("A") # _todo, tooltips and cell_context items added to.. assert len(s._todo) > 0 assert s.tooltips assert len(s.cell_context) > 0 + assert s.hidden_index is True + assert len(s.hidden_columns) > 0 s = s._compute() # ctx item affected when a render takes place. _todo is maintained @@ -190,6 +193,8 @@ def test_clear(self): assert len(s._todo) == 0 assert not s.tooltips assert len(s.cell_context) == 0 + assert s.hidden_index is False + assert len(s.hidden_columns) == 0 def test_render(self): df = DataFrame({"A": [0, 1]})