Skip to content

BUG: Update Styler.clear method to clear all #40664

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

Merged
merged 12 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Other enhancements
- :class:`RangeIndex` can now be constructed by passing a ``range`` object directly e.g. ``pd.RangeIndex(range(3))`` (:issue:`12067`)
- :meth:`round` being enabled for the nullable integer and floating dtypes (:issue:`38844`)
- :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`)
- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually one minor item: can you move this line up to where the other STyler changes are reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing, will update in a bit


.. ---------------------------------------------------------------------------

Expand Down
7 changes: 6 additions & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]})
Expand Down