Skip to content

BUG: allow kwargs in Styler apply_index and map_index#1725

Open
eosti wants to merge 1 commit intopandas-dev:mainfrom
eosti:styler-kwargs
Open

BUG: allow kwargs in Styler apply_index and map_index#1725
eosti wants to merge 1 commit intopandas-dev:mainfrom
eosti:styler-kwargs

Conversation

@eosti
Copy link
Copy Markdown

@eosti eosti commented Apr 15, 2026

Adds ability to pass a function with **kwargs to Styler apply_index and map_index. The apply and map functions already supported this.

self, series: Series, /, *args: Any, **kwargs: Any
) -> list[Any] | Series: ...

class _SeriesStrFunc(Protocol):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried on my end and this protocol thing works but is a bit of overkill for what you are trying to do here. Turns out since args and kwargs here are just Any, you can drop it in exchange for:
Callable[Concatenate[Series, ...]], list[str] | np_ndarray_str | Series[str]]
This will make it a lot cleaner and simpler to understand.

Copy link
Copy Markdown
Member

@loicdiridollou loicdiridollou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an opportunity to simplify here, the tests though are looking good!

Comment thread tests/test_styler.py
check(assert_type(DF.style.apply_index(f1), Styler), Styler)

# GH 1723
def highlight_odd(index: pd.Series, /, color: str) -> list[str]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the /, it should work without it since it is hardly a usecase you see in production code.

Copy link
Copy Markdown
Member

@loicdiridollou loicdiridollou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Styler apply_* and map functions do not accept **kwargs

2 participants