Skip to content

Commit 2d69a57

Browse files
authored
Add index and columns as properties to Styler (#1135)
* add index and columns as properties in Styler * add test for index and columns - added in previous commit * fix imports * precommit manual run
1 parent cf4d68d commit 2d69a57

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas-stubs/io/formats/style.pyi

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111

1212
from matplotlib.colors import Colormap
1313
import numpy as np
14+
from pandas import Index
1415
from pandas.core.frame import DataFrame
1516
from pandas.core.series import Series
1617

@@ -52,6 +53,10 @@ class _DataFrameFunc(Protocol):
5253
) -> npt.NDArray | DataFrame: ...
5354

5455
class Styler(StylerRenderer):
56+
@property
57+
def columns(self) -> Index[Any]: ...
58+
@property
59+
def index(self) -> Index[Any]: ...
5560
def __init__(
5661
self,
5762
data: DataFrame | Series,

tests/test_styler.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import numpy.typing as npt
1414
from pandas import (
1515
DataFrame,
16+
Index,
1617
Series,
1718
)
1819
from pandas._testing import ensure_clean
@@ -224,3 +225,9 @@ def test_subset() -> None:
224225
check(assert_type(DF.style.highlight_min(subset=IndexSlice[1:2]), Styler), Styler)
225226
check(assert_type(DF.style.highlight_min(subset=[1]), Styler), Styler)
226227
check(assert_type(DF.style.highlight_min(subset=DF.columns[1:]), Styler), Styler)
228+
229+
230+
def test_styler_columns_and_index() -> None:
231+
styler = DF.style
232+
check(assert_type(styler.columns, Index), Index)
233+
check(assert_type(styler.index, Index), Index)

0 commit comments

Comments
 (0)