From 8b9e343cf0c8cf14c045b5162ca78be261a1b231 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Sat, 4 Sep 2021 20:49:56 +0200 Subject: [PATCH 1/2] hide_columns does not hide index names --- pandas/io/formats/style_render.py | 1 - pandas/tests/io/formats/style/test_style.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 0c6ced17b623e..264ea803db7f3 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -387,7 +387,6 @@ def _translate_header( self.data.index.names and com.any_not_none(*self.data.index.names) and not all(self.hide_index_) - and not all(self.hide_columns_) and not self.hide_index_names ): index_names = [ diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index e6ac2e4ae81e1..2fc071a5abc5f 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -1062,7 +1062,8 @@ def test_hide_column_headers(self): self.df.index.name = "some_name" ctx = self.df.style.hide_columns()._translate(True, True) - assert len(ctx["head"]) == 0 # no header for index names, changed in #42101 + assert len(ctx["head"]) == 1 + # no header for index names, changed in #42101, reverted in xxxxx def test_hide_single_index(self): # GH 14194 From b7c4e15728a050ccd5cbfed337163b1293498551 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Sat, 4 Sep 2021 21:09:50 +0200 Subject: [PATCH 2/2] issues and whats new --- doc/source/whatsnew/v1.4.0.rst | 2 +- pandas/tests/io/formats/style/test_style.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 4cd76346a4a8f..10bc29d3e73df 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -76,7 +76,7 @@ Styler - :meth:`.Styler.bar` introduces additional arguments to control alignment and display (:issue:`26070`, :issue:`36419`), and it also validates the input arguments ``width`` and ``height`` (:issue:`42511`). - :meth:`.Styler.to_latex` introduces keyword argument ``environment``, which also allows a specific "longtable" entry through a separate jinja2 template (:issue:`41866`). - :meth:`.Styler.to_html` introduces keyword arguments ``sparse_index``, ``sparse_columns``, ``bold_headers``, ``caption`` (:issue:`41946`, :issue:`43149`). - - Keyword argument ``level`` is added to :meth:`.Styler.hide_index` and :meth:`.Styler.hide_columns` for optionally controlling hidden levels in a MultiIndex (:issue:`25475`) + - Keyword arguments ``level`` and ``names`` added to :meth:`.Styler.hide_index` and :meth:`.Styler.hide_columns` for additional control of visibility of MultiIndexes and index names (:issue:`25475`, :issue:`43404`, :issue:`43346`) - Global options have been extended to configure default ``Styler`` properties including formatting and encoding and mathjax options and LaTeX (:issue:`41395`) Formerly Styler relied on ``display.html.use_mathjax``, which has now been replaced by ``styler.html.mathjax``. diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 2fc071a5abc5f..1ab2fcd380017 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -1063,7 +1063,7 @@ def test_hide_column_headers(self): self.df.index.name = "some_name" ctx = self.df.style.hide_columns()._translate(True, True) assert len(ctx["head"]) == 1 - # no header for index names, changed in #42101, reverted in xxxxx + # index names still visible, changed in #42101, reverted in 43404 def test_hide_single_index(self): # GH 14194