You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Following the example in pandas website, I defined a function to highlight the maximum of each row. However, mypy does not recognize the call signature.
To Reproduce
Minimal working example
from typing import List
import numpy as np
import pandas as pd
def highlight_max(x: 'pd.Series[int]', color: str) -> List[str]:
"""Highlight max."""
return [f"color: {color}" if val == x.max() else "" for val in x]
df = pd.DataFrame(np.random.randint(0, high=100, size=(10, 3)))
styler = df.style.apply(highlight_max, color='red', axis=1)
styler.to_html("output.html")
I'm using mypy
Show the error message received from that type checker while checking your example.
In terminal
Thanks for the report. This is non-trivial to fix. We have overloads that test whether you are passing a Callable that takes a Series or DataFrame, as that pairs with the axis argument of Styler.apply(). But there really aren't signatures for callables that have keyword arguments, and the recommended way to handle that is to use Protocol. But that has issues - see microsoft/pyright#7898 because it forces the callable to have a specific name for the first argument.
I'll have to see what the typing experts have to say about this.
Describe the bug
Following the example in pandas website, I defined a function to highlight the maximum of each row. However,
mypy
does not recognize the call signature.To Reproduce
mypy
In terminal
Please complete the following information:
pandas-stubs
: frompip list
:pandas-stubs 2.2.1.240316
The text was updated successfully, but these errors were encountered: