Skip to content

Commit 8d9792b

Browse files
authored
TYP: func in core.apply.Apply.__init__ (#53365)
1 parent 8253d4e commit 8d9792b

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:
@@ -1201,7 +1201,7 @@ def transform(self):
12011201

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

12571257
if relabeling:
12581258
func, columns, order = normalize_keyword_aggregation(kwargs)
1259+
assert func is not None
12591260

12601261
return relabeling, func, columns, order
12611262

0 commit comments

Comments
 (0)