Skip to content

Commit 7a47b42

Browse files
GH1226 Add Styler.map to the stubs
1 parent 93a9e11 commit 7a47b42

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas-stubs/io/formats/style.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class Styler(StylerRenderer):
7171
formatter: ExtFormatter | None = ...,
7272
) -> None: ...
7373
def concat(self, other: Styler) -> Styler: ...
74+
def map(
75+
self, func: Callable, subset: Subset | None = ..., **kwargs: Any
76+
) -> Styler: ...
7477
def set_tooltips(
7578
self,
7679
ttips: DataFrame,

tests/test_styler.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
DF = DataFrame({"a": [1, 2, 3], "b": [3.14, 2.72, 1.61]})
3232

33-
3433
PWD = pathlib.Path(os.path.split(os.path.abspath(__file__))[0])
3534

3635
if TYPE_CHECKING:
@@ -233,3 +232,12 @@ def test_styler_columns_and_index() -> None:
233232
styler = DF.style
234233
check(assert_type(styler.columns, Index), Index)
235234
check(assert_type(styler.index, Index), Index)
235+
236+
237+
def test_styler_map() -> None:
238+
"""Test type returned with Styler.map GH1226."""
239+
df = DataFrame(data={"col1": [1, -2], "col2": [-3, 4]})
240+
check(
241+
assert_type(df.style.map(lambda v: "color: red;" if v < 0 else None), Styler),
242+
Styler,
243+
)

0 commit comments

Comments
 (0)