Skip to content

TYP: func in core.apply.Apply.__init__ #53365

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 1 commit into from
May 24, 2023
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
19 changes: 10 additions & 9 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ def frame_apply(

class Apply(metaclass=abc.ABCMeta):
axis: AxisInt
orig_f: AggFuncType
f: AggFuncType

def __init__(
self,
obj: AggObjType,
func,
func: AggFuncType,
raw: bool,
result_type: str | None,
*,
Expand All @@ -127,21 +129,19 @@ def __init__(

self.result_type = result_type

f: AggFuncType
# curry if needed
if (
(kwargs or args)
and not isinstance(func, (np.ufunc, str))
and not is_list_like(func)
):
if callable(func) and (kwargs or args) and not isinstance(func, np.ufunc):

def f(x):
assert callable(func) # needed for mypy
return func(x, *args, **kwargs)

else:
f = func

self.orig_f: AggFuncType = func
self.f: AggFuncType = f
self.orig_f = func
self.f = f

@abc.abstractmethod
def apply(self) -> DataFrame | Series:
Expand Down Expand Up @@ -1201,7 +1201,7 @@ def transform(self):

def reconstruct_func(
func: AggFuncType | None, **kwargs
) -> tuple[bool, AggFuncType | None, list[str] | None, npt.NDArray[np.intp] | None]:
) -> tuple[bool, AggFuncType, list[str] | None, npt.NDArray[np.intp] | None]:
"""
This is the internal function to reconstruct func given if there is relabeling
or not and also normalize the keyword to get new order of columns.
Expand Down Expand Up @@ -1256,6 +1256,7 @@ def reconstruct_func(

if relabeling:
func, columns, order = normalize_keyword_aggregation(kwargs)
assert func is not None

return relabeling, func, columns, order

Expand Down