diff --git a/pandas-stubs/io/formats/style.pyi b/pandas-stubs/io/formats/style.pyi index 4724726f8..295363421 100644 --- a/pandas-stubs/io/formats/style.pyi +++ b/pandas-stubs/io/formats/style.pyi @@ -11,6 +11,7 @@ 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 @@ -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, diff --git a/tests/test_styler.py b/tests/test_styler.py index 42f7830d9..976b5a110 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -13,6 +13,7 @@ import numpy.typing as npt from pandas import ( DataFrame, + Index, Series, ) from pandas._testing import ensure_clean @@ -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)