Skip to content

Commit 8249736

Browse files
committed
TYP: func in core.apply.Apply.__init__ (pandas-dev#53365)
1 parent 57309e6 commit 8249736

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pandas/core/apply.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ def frame_apply(
103103

104104
class Apply(metaclass=abc.ABCMeta):
105105
axis: AxisInt
106+
orig_f: AggFuncType
107+
f: AggFuncType
106108

107109
def __init__(
108110
self,
109111
obj: AggObjType,
110-
func,
112+
func: AggFuncType,
111113
raw: bool,
112114
result_type: str | None,
113115
*,
@@ -127,21 +129,19 @@ def __init__(
127129

128130
self.result_type = result_type
129131

132+
f: AggFuncType
130133
# curry if needed
131-
if (
132-
(kwargs or args)
133-
and not isinstance(func, (np.ufunc, str))
134-
and not is_list_like(func)
135-
):
134+
if callable(func) and (kwargs or args) and not isinstance(func, np.ufunc):
136135

137136
def f(x):
137+
assert callable(func) # needed for mypy
138138
return func(x, *args, **kwargs)
139139

140140
else:
141141
f = func
142142

143-
self.orig_f: AggFuncType = func
144-
self.f: AggFuncType = f
143+
self.orig_f = func
144+
self.f = f
145145

146146
@abc.abstractmethod
147147
def apply(self) -> DataFrame | Series:
@@ -1199,7 +1199,7 @@ def transform(self):
11991199

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

12551255
if relabeling:
12561256
func, columns, order = normalize_keyword_aggregation(kwargs)
1257+
assert func is not None
12571258

12581259
return relabeling, func, columns, order
12591260

0 commit comments

Comments
 (0)