Skip to content

Commit 3e9fcd4

Browse files
committed
styler
1 parent fc1e498 commit 3e9fcd4

2 files changed

Lines changed: 22 additions & 46 deletions

File tree

pandas-stubs/io/formats/style.pyi

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ from typing import (
88
Any,
99
Concatenate,
1010
Literal,
11-
Protocol,
1211
Self,
1312
overload,
1413
)
@@ -52,26 +51,6 @@ from pandas.io.formats.style_render import (
5251
Subset,
5352
)
5453

55-
class _SeriesFunc(Protocol):
56-
def __call__(
57-
self, series: Series, /, *args: Any, **kwargs: Any
58-
) -> list[Any] | Series: ...
59-
60-
class _SeriesStrFunc(Protocol):
61-
def __call__(
62-
self, series: Series[str], /, *args: Any, **kwargs: Any
63-
) -> list[str] | Series[str]: ...
64-
65-
class _DataFrameFunc(Protocol):
66-
def __call__(
67-
self, series: DataFrame, /, *args: Any, **kwargs: Any
68-
) -> np_ndarray | DataFrame: ...
69-
70-
class _MapCallable(Protocol):
71-
def __call__(
72-
self, first_arg: Scalar, /, *args: Any, **kwargs: Any
73-
) -> str | None: ...
74-
7554
class Styler(StylerRenderer):
7655
def __init__(
7756
self,
@@ -90,16 +69,12 @@ class Styler(StylerRenderer):
9069
formatter: ExtFormatter | None = ...,
9170
) -> None: ...
9271
def concat(self, other: Styler) -> Styler: ...
93-
@overload
94-
def map(
95-
self,
96-
func: Callable[[Scalar], str | None],
97-
subset: Subset[Hashable] | None = ...,
98-
) -> Styler: ...
99-
@overload
10072
def map(
10173
self,
102-
func: _MapCallable,
74+
func: (
75+
Callable[[Scalar], str | None]
76+
| Callable[Concatenate[Scalar, ...], str | None]
77+
),
10378
subset: Subset[Hashable] | None = ...,
10479
**kwargs: Any,
10580
) -> Styler: ...
@@ -267,32 +242,43 @@ class Styler(StylerRenderer):
267242
@overload
268243
def apply(
269244
self,
270-
func: _SeriesFunc | Callable[[Series], list[Any] | Series],
245+
func: (
246+
Callable[[Series], list[Any] | Series]
247+
| Callable[Concatenate[Series, ...], list[Any] | Series]
248+
),
271249
axis: Axis = ...,
272250
subset: Subset[Hashable] | None = ...,
273251
**kwargs: Any,
274252
) -> Styler: ...
275253
@overload
276254
def apply(
277255
self,
278-
func: _DataFrameFunc | Callable[[DataFrame], np_ndarray | DataFrame],
256+
func: (
257+
Callable[[DataFrame], np_ndarray | DataFrame]
258+
| Callable[Concatenate[DataFrame, ...], np_ndarray | DataFrame]
259+
),
279260
axis: None,
280261
subset: Subset[Hashable] | None = ...,
281262
**kwargs: Any,
282263
) -> Styler: ...
283264
def apply_index(
284265
self,
285266
func: (
286-
_SeriesStrFunc
287-
| Callable[[Series], list[str] | np_ndarray_str | Series[str]]
267+
Callable[[Series], list[str] | np_ndarray_str | Series[str]]
268+
| Callable[
269+
Concatenate[Series, ...], list[str] | np_ndarray_str | Series[str]
270+
]
288271
),
289272
axis: Axis = ...,
290273
level: Level | list[Level] | None = ...,
291274
**kwargs: Any,
292275
) -> Styler: ...
293276
def map_index(
294277
self,
295-
func: _MapCallable | Callable[[Scalar], str | None],
278+
func: (
279+
Callable[[Scalar], str | None]
280+
| Callable[Concatenate[Scalar, ...], str | None]
281+
),
296282
axis: Axis = ...,
297283
level: Level | list[Level] | None = ...,
298284
**kwargs: Any,

tests/test_styler.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ def highlight_max(x: Series[int], /, color: str) -> list[str]:
6060
return [f"color: {color}" if val == x.max() else "" for val in x]
6161

6262
check(
63-
# TODO: facebook/pyrefly#0
64-
# pyrefly: ignore[assert-type,no-matching-overload]
65-
assert_type(DF.style.apply(highlight_max, color="red", axis=1), Styler),
66-
Styler,
63+
assert_type(DF.style.apply(highlight_max, color="red", axis=1), Styler), Styler
6764
)
6865

6966

@@ -84,10 +81,7 @@ def highlight_odd(index: pd.Series, color: str) -> list[str]:
8481

8582
check(
8683
assert_type(
87-
# TODO: facebook/pyrefly#0
88-
# pyrefly: ignore[bad-argument-type]
89-
DF.style.apply_index(highlight_odd, axis=0, color="purple"),
90-
Styler,
84+
DF.style.apply_index(highlight_odd, axis=0, color="purple"), Styler
9185
),
9286
Styler,
9387
)
@@ -102,8 +96,6 @@ def f(s: Scalar) -> str | None:
10296
def f1(s: Scalar, color: str) -> str | None:
10397
return f"background-color: {color};" if s == "b" else None
10498

105-
# TODO: facebook/pyrefly#0
106-
# pyrefly: ignore[bad-argument-type]
10799
check(assert_type(DF.style.map_index(f1, color="pink", axis=0), Styler), Styler)
108100

109101

@@ -286,8 +278,6 @@ def color_negative(v: Scalar, /, color: str) -> str | None:
286278

287279
df = DataFrame(np.random.randn(5, 2), columns=["A", "B"])
288280

289-
# TODO: facebook/pyrefly#0
290-
# pyrefly: ignore[assert-type,no-matching-overload]
291281
check(assert_type(df.style.map(color_negative, color="red"), Styler), Styler)
292282

293283

0 commit comments

Comments
 (0)