Skip to content

Commit 75b9ad9

Browse files
GH1226 PR Feedback
1 parent 85eac7a commit 75b9ad9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pandas-stubs/io/formats/style.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,18 @@ class Styler(StylerRenderer):
7171
formatter: ExtFormatter | None = ...,
7272
) -> None: ...
7373
def concat(self, other: Styler) -> Styler: ...
74+
@overload
7475
def map(
7576
self,
7677
func: Callable[[Scalar], str | None],
7778
subset: Subset | None = ...,
78-
**kwargs: dict[str, Any],
79+
) -> Styler: ...
80+
@overload
81+
def map(
82+
self,
83+
func: Callable[..., str | None],
84+
subset: Subset | None = ...,
85+
**kwargs: Any,
7986
) -> Styler: ...
8087
def set_tooltips(
8188
self,

tests/test_styler.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import os
44
import pathlib
5-
from typing import TYPE_CHECKING
5+
from typing import (
6+
TYPE_CHECKING,
7+
Any,
8+
)
69

710
from jinja2.environment import (
811
Environment,
@@ -246,3 +249,16 @@ def test_styler_map() -> None:
246249
),
247250
Styler,
248251
)
252+
253+
def color_negative(v: Scalar, color: str) -> str | None:
254+
return f"color: {color};" if isinstance(v, float) and v < 0 else None
255+
256+
df = DataFrame(np.random.randn(5, 2), columns=["A", "B"])
257+
258+
check(
259+
assert_type(
260+
df.style.map(color_negative, color="red"),
261+
Styler,
262+
),
263+
Styler,
264+
)

0 commit comments

Comments
 (0)