Skip to content

Commit b30d777

Browse files
authored
Add stub for Styler.map_index (#905)
* fix: add stub for Styler.map_index * add test for Styler.map_index * Fix map_index type definition * Update test_map_index to show example from docs * Run pre-commit
1 parent 9dd9eee commit b30d777

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pandas-stubs/io/formats/style.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ class Styler(StylerRenderer):
218218
level: Level | list[Level] | None = ...,
219219
**kwargs: Any,
220220
) -> Styler: ...
221+
def map_index(
222+
self,
223+
func: Callable[[Scalar], str | None],
224+
axis: Axis = ...,
225+
level: Level | list[Level] | None = ...,
226+
**kwargs,
227+
) -> Styler: ...
221228
def set_table_attributes(self, attributes: str) -> Styler: ...
222229
def export(self) -> StyleExportDict: ...
223230
def use(self, styles: StyleExportDict) -> Styler: ...

tests/test_styler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import pytest
2020
from typing_extensions import assert_type
2121

22+
from pandas._typing import Scalar
23+
2224
from tests import check
2325

2426
from pandas.io.formats.style import Styler
@@ -63,6 +65,13 @@ def f1(s: Series) -> Series[str]:
6365
check(assert_type(DF.style.apply_index(f1), Styler), Styler)
6466

6567

68+
def test_map_index() -> None:
69+
def f(s: Scalar) -> str | None:
70+
return "background-color: yellow;" if s == "B" else None
71+
72+
check(assert_type(DF.style.map_index(f), Styler), Styler)
73+
74+
6675
def test_background_gradient() -> None:
6776
check(assert_type(DF.style.background_gradient(), Styler), Styler)
6877

0 commit comments

Comments
 (0)