From 4d86f52156082e2735ec6c1411a4512c68877f13 Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 2 Feb 2022 17:41:51 +0100 Subject: [PATCH 1/5] Enhance consistency on Styler hide methods --- pandas/io/formats/style.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index f97f558fd0e0b..dd3788a6e2ce2 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2498,11 +2498,11 @@ def hide_index( Styler.hide: Hide the entire index / columns, or specific rows / columns. """ warnings.warn( - "this method is deprecated in favour of `Styler.hide(axis='index')`", + "this method is deprecated in favour of `Styler.hide(axis=\"index\")`", FutureWarning, stacklevel=find_stack_level(), ) - return self.hide(axis=0, level=level, subset=subset, names=names) + return self.hide(axis="index", level=level, subset=subset, names=names) def hide_columns( self, @@ -2551,16 +2551,16 @@ def hide_columns( Styler.hide: Hide the entire index / columns, or specific rows / columns. """ warnings.warn( - "this method is deprecated in favour of `Styler.hide(axis='columns')`", + "this method is deprecated in favour of `Styler.hide(axis=\"columns\")`", FutureWarning, stacklevel=find_stack_level(), ) - return self.hide(axis=1, level=level, subset=subset, names=names) + return self.hide(axis="columns", level=level, subset=subset, names=names) def hide( self, subset: Subset | None = None, - axis: Axis = 0, + axis: Axis = "index", level: Level | list[Level] | None = None, names: bool = False, ) -> Styler: From 96de257b64701f4d542273b2e7fa55840dc16d6e Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 2 Feb 2022 17:48:06 +0100 Subject: [PATCH 2/5] Docs and checks --- doc/source/whatsnew/v1.4.1.rst | 2 +- pandas/io/formats/style.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 3dd0fcdb5b87d..be9b24e80dedf 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -41,7 +41,7 @@ Bug fixes Other ~~~~~ - Reverted performance speedup of :meth:`DataFrame.corr` for ``method=pearson`` to fix precision regression (:issue:`45640`, :issue:`42761`) -- +- Improved messages and parameters consistency on Styler methods ``hide()``, ``hide_columns()`` and ``hide_index()``. .. --------------------------------------------------------------------------- diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index dd3788a6e2ce2..94ded38b6f8ca 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2498,7 +2498,7 @@ def hide_index( Styler.hide: Hide the entire index / columns, or specific rows / columns. """ warnings.warn( - "this method is deprecated in favour of `Styler.hide(axis=\"index\")`", + 'this method is deprecated in favour of `Styler.hide(axis="index")`', FutureWarning, stacklevel=find_stack_level(), ) @@ -2551,7 +2551,7 @@ def hide_columns( Styler.hide: Hide the entire index / columns, or specific rows / columns. """ warnings.warn( - "this method is deprecated in favour of `Styler.hide(axis=\"columns\")`", + 'this method is deprecated in favour of `Styler.hide(axis="columns")`', FutureWarning, stacklevel=find_stack_level(), ) From 31e593860d9af831f197668e9d03441d3d3bfdfe Mon Sep 17 00:00:00 2001 From: staticdev Date: Thu, 3 Feb 2022 09:50:09 +0100 Subject: [PATCH 3/5] Make set_sticky consistent with all other methods --- pandas/io/formats/style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 94ded38b6f8ca..45cacaacd6b11 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2147,7 +2147,7 @@ def set_caption(self, caption: str | tuple) -> Styler: def set_sticky( self, - axis: Axis = 0, + axis: Axis = "index", pixel_size: int | None = None, levels: Level | list[Level] | None = None, ) -> Styler: From a037c609b6931a646b2ab0c713b4b209447c4979 Mon Sep 17 00:00:00 2001 From: staticdev Date: Thu, 3 Feb 2022 13:15:20 +0100 Subject: [PATCH 4/5] Remove whatsnew --- doc/source/whatsnew/v1.4.1.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index be9b24e80dedf..7d930839b5756 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -41,7 +41,6 @@ Bug fixes Other ~~~~~ - Reverted performance speedup of :meth:`DataFrame.corr` for ``method=pearson`` to fix precision regression (:issue:`45640`, :issue:`42761`) -- Improved messages and parameters consistency on Styler methods ``hide()``, ``hide_columns()`` and ``hide_index()``. .. --------------------------------------------------------------------------- From d464072e2f87d3508ad68e943ca6d3669bd3097a Mon Sep 17 00:00:00 2001 From: staticdev Date: Mon, 28 Feb 2022 21:19:18 +0100 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: JHM Darbyshire <24256554+attack68@users.noreply.github.com> --- pandas/io/formats/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 6663adb8fdf57..b9e66fa3e12d5 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2230,7 +2230,7 @@ def set_caption(self, caption: str | tuple) -> Styler: def set_sticky( self, - axis: Axis = "index", + axis: Axis = 0, pixel_size: int | None = None, levels: Level | list[Level] | None = None, ) -> Styler: @@ -2645,7 +2645,7 @@ def hide_columns( def hide( self, subset: Subset | None = None, - axis: Axis = "index", + axis: Axis = 0, level: Level | list[Level] | None = None, names: bool = False, ) -> Styler: