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 f1c5f3ac3a2bd..4afcd0b310fcc 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -353,6 +353,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 64c62a00ff29d..ffe1e8e547322 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -1131,7 +1131,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