Skip to content

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

@eosti

Description

@eosti

Describe the bug
This is an extension of #919 which was fixed by #921.

There's a few Styler functions that accept **kwargs being passed to func, but the stubs only support **kwargs in the func signature for Styler.apply(). I'm working with apply_index right now, but map and map_index both should be able to accept **kwargs according to the docs.

To Reproduce

import numpy as np
import pandas as pd


def highlight_odd(index: pd.Series, /, color: str) -> list[str]:
    style = [f"color: {color}" if x % 2 else "" for x in index]
    return style


df = pd.DataFrame(np.random.randint(0, high=100, size=(10, 3)))
styler = df.style.apply_index(highlight_odd, color='red')
styler.to_html("output.html")

Using pyright:

    Type "(index: Series[Any], /, color: str) -> list[str]" is not assignable to type "(Series[Any]) -> (NDArray[str_] | list[str] | Series[str])"
      Extra parameter "color" (reportArgumentType)
1 error, 0 warnings, 0 informations

Please complete the following information:

  • OS: [e.g. Windows, Linux, MacOS]
  • OS Version: 26.3.1
  • python version: 3.12.12
  • version of type checker: pyright 1.1.408
  • version of installed pandas-stubs:  3.0.0.260204

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions