From b865fee42abd3d1dd75bb5158140cefcf9242827 Mon Sep 17 00:00:00 2001 From: "rishab260@hotmail.com" Date: Sat, 1 Mar 2025 18:01:44 +0530 Subject: [PATCH 1/4] add index and columns as properties in Styler --- pandas-stubs/io/formats/style.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas-stubs/io/formats/style.pyi b/pandas-stubs/io/formats/style.pyi index 4724726f8..2e63deeca 100644 --- a/pandas-stubs/io/formats/style.pyi +++ b/pandas-stubs/io/formats/style.pyi @@ -13,6 +13,7 @@ from matplotlib.colors import Colormap import numpy as np from pandas.core.frame import DataFrame from pandas.core.series import Series +from pandas import Index from pandas._typing import ( Axis, @@ -52,6 +53,10 @@ class _DataFrameFunc(Protocol): ) -> npt.NDArray | DataFrame: ... class Styler(StylerRenderer): + @property + def columns(self) -> Index[Any]: ... + @property + def index(self) -> Index[Any]: ... def __init__( self, data: DataFrame | Series, From 4aa7e728c9e0b523331ce2b30bcb211fb953ada0 Mon Sep 17 00:00:00 2001 From: "rishab260@hotmail.com" Date: Sat, 1 Mar 2025 18:02:35 +0530 Subject: [PATCH 2/4] add test for index and columns - added in previous commit --- tests/test_styler.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_styler.py b/tests/test_styler.py index 42f7830d9..39bb6f5d7 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -20,6 +20,7 @@ from typing_extensions import assert_type from pandas._typing import Scalar +from pandas import Index from tests import check @@ -224,3 +225,9 @@ def test_subset() -> None: check(assert_type(DF.style.highlight_min(subset=IndexSlice[1:2]), Styler), Styler) check(assert_type(DF.style.highlight_min(subset=[1]), Styler), Styler) check(assert_type(DF.style.highlight_min(subset=DF.columns[1:]), Styler), Styler) + + +def test_styler_columns_and_index() -> None: + styler = DF.style + check(assert_type(styler.columns, Index), Index) + check(assert_type(styler.index, Index), Index) From edb440d9c5bf415e5a553cc6d67d06b3d1c1b37b Mon Sep 17 00:00:00 2001 From: "rishab260@hotmail.com" Date: Sat, 1 Mar 2025 18:49:20 +0530 Subject: [PATCH 3/4] fix imports --- tests/test_styler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_styler.py b/tests/test_styler.py index 39bb6f5d7..e3c420eba 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -14,13 +14,13 @@ from pandas import ( DataFrame, Series, + Index ) from pandas._testing import ensure_clean import pytest from typing_extensions import assert_type from pandas._typing import Scalar -from pandas import Index from tests import check From 19b67d5833a9083bdbd41495c875ae180df0ab3f Mon Sep 17 00:00:00 2001 From: "rishab260@hotmail.com" Date: Sun, 2 Mar 2025 13:03:15 +0530 Subject: [PATCH 4/4] precommit manual run --- pandas-stubs/io/formats/style.pyi | 2 +- tests/test_styler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas-stubs/io/formats/style.pyi b/pandas-stubs/io/formats/style.pyi index 2e63deeca..295363421 100644 --- a/pandas-stubs/io/formats/style.pyi +++ b/pandas-stubs/io/formats/style.pyi @@ -11,9 +11,9 @@ from typing import ( from matplotlib.colors import Colormap import numpy as np +from pandas import Index from pandas.core.frame import DataFrame from pandas.core.series import Series -from pandas import Index from pandas._typing import ( Axis, diff --git a/tests/test_styler.py b/tests/test_styler.py index e3c420eba..976b5a110 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -13,8 +13,8 @@ import numpy.typing as npt from pandas import ( DataFrame, + Index, Series, - Index ) from pandas._testing import ensure_clean import pytest