Skip to content

TYP: callable refactor for apply methods in styler #43148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ def clear(self) -> None:

def _apply(
self,
func: Callable[..., Styler],
func: Callable,
axis: Axis | None = 0,
subset: Subset | None = None,
**kwargs,
Expand Down Expand Up @@ -1195,7 +1195,7 @@ def _apply(

def apply(
self,
func: Callable[..., Styler],
func: Callable,
axis: Axis | None = 0,
subset: Subset | None = None,
**kwargs,
Expand Down Expand Up @@ -1290,7 +1290,7 @@ def apply(

def _apply_index(
self,
func: Callable[..., Styler],
func: Callable,
axis: int | str = 0,
level: Level | list[Level] | None = None,
method: str = "apply",
Expand Down Expand Up @@ -1325,7 +1325,7 @@ def _apply_index(
)
def apply_index(
self,
func: Callable[..., Styler],
func: Callable,
axis: int | str = 0,
level: Level | list[Level] | None = None,
**kwargs,
Expand Down Expand Up @@ -1411,7 +1411,7 @@ def apply_index(
)
def applymap_index(
self,
func: Callable[..., Styler],
func: Callable,
axis: int | str = 0,
level: Level | list[Level] | None = None,
**kwargs,
Expand Down Expand Up @@ -2597,11 +2597,7 @@ def f(data: DataFrame, props: str) -> np.ndarray:

if props is None:
props = f"background-color: {null_color};"
# error: Argument 1 to "apply" of "Styler" has incompatible type
# "Callable[[DataFrame, str], ndarray]"; expected "Callable[..., Styler]"
return self.apply(
f, axis=None, subset=subset, props=props # type: ignore[arg-type]
)
return self.apply(f, axis=None, subset=subset, props=props)

def highlight_max(
self,
Expand Down Expand Up @@ -2645,10 +2641,8 @@ def highlight_max(

if props is None:
props = f"background-color: {color};"
# error: Argument 1 to "apply" of "Styler" has incompatible type
# "Callable[[FrameOrSeries, str], ndarray]"; expected "Callable[..., Styler]"
return self.apply(
partial(_highlight_value, op="max"), # type: ignore[arg-type]
partial(_highlight_value, op="max"),
axis=axis,
subset=subset,
props=props,
Expand Down Expand Up @@ -2696,10 +2690,8 @@ def highlight_min(

if props is None:
props = f"background-color: {color};"
# error: Argument 1 to "apply" of "Styler" has incompatible type
# "Callable[[FrameOrSeries, str], ndarray]"; expected "Callable[..., Styler]"
return self.apply(
partial(_highlight_value, op="min"), # type: ignore[arg-type]
partial(_highlight_value, op="min"),
axis=axis,
subset=subset,
props=props,
Expand Down Expand Up @@ -2805,7 +2797,7 @@ def highlight_between(
if props is None:
props = f"background-color: {color};"
return self.apply(
_highlight_between, # type: ignore[arg-type]
_highlight_between,
axis=axis,
subset=subset,
props=props,
Expand Down Expand Up @@ -2911,7 +2903,7 @@ def highlight_quantile(
if props is None:
props = f"background-color: {color};"
return self.apply(
_highlight_between, # type: ignore[arg-type]
_highlight_between,
axis=axis_apply,
subset=subset,
props=props,
Expand Down