From 3150de99bc21bfb724d68ee1fa740efa37810799 Mon Sep 17 00:00:00 2001 From: attack68 <24256554+attack68@users.noreply.github.com> Date: Tue, 3 Aug 2021 19:15:13 +0200 Subject: [PATCH] Backport PR #42839: BUG: `styler.hide_columns` now hides the index name header row --- doc/source/whatsnew/v1.3.2.rst | 2 +- pandas/io/formats/style_render.py | 1 + pandas/tests/io/formats/style/test_style.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.3.2.rst b/doc/source/whatsnew/v1.3.2.rst index 8723b1b766485..9b412d6d46c5e 100644 --- a/doc/source/whatsnew/v1.3.2.rst +++ b/doc/source/whatsnew/v1.3.2.rst @@ -31,7 +31,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ - 1D slices over extension types turn into N-dimensional slices over ExtensionArrays (:issue:`42430`) -- +- :meth:`.Styler.hide_columns` now hides the index name header row as well as column headers (:issue:`42101`) .. --------------------------------------------------------------------------- diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 616b89f9e519f..97a05329507c9 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -356,6 +356,7 @@ def _translate_header( self.data.index.names and com.any_not_none(*self.data.index.names) and not self.hide_index_ + and not self.hide_columns_ ): index_names = [ _element( diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index f2c2f673909d4..99c725ed8df69 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -1109,7 +1109,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 # only a single row for index names: no col heads + assert len(ctx["head"]) == 0 # no header for index names, changed in #42101 def test_hide_single_index(self): # GH 14194