@@ -103,11 +103,13 @@ def frame_apply(
103
103
104
104
class Apply (metaclass = abc .ABCMeta ):
105
105
axis : AxisInt
106
+ orig_f : AggFuncType
107
+ f : AggFuncType
106
108
107
109
def __init__ (
108
110
self ,
109
111
obj : AggObjType ,
110
- func ,
112
+ func : AggFuncType ,
111
113
raw : bool ,
112
114
result_type : str | None ,
113
115
* ,
@@ -127,21 +129,19 @@ def __init__(
127
129
128
130
self .result_type = result_type
129
131
132
+ f : AggFuncType
130
133
# 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 ):
136
135
137
136
def f (x ):
137
+ assert callable (func ) # needed for mypy
138
138
return func (x , * args , ** kwargs )
139
139
140
140
else :
141
141
f = func
142
142
143
- self .orig_f : AggFuncType = func
144
- self .f : AggFuncType = f
143
+ self .orig_f = func
144
+ self .f = f
145
145
146
146
@abc .abstractmethod
147
147
def apply (self ) -> DataFrame | Series :
@@ -1201,7 +1201,7 @@ def transform(self):
1201
1201
1202
1202
def reconstruct_func (
1203
1203
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 ]:
1205
1205
"""
1206
1206
This is the internal function to reconstruct func given if there is relabeling
1207
1207
or not and also normalize the keyword to get new order of columns.
@@ -1256,6 +1256,7 @@ def reconstruct_func(
1256
1256
1257
1257
if relabeling :
1258
1258
func , columns , order = normalize_keyword_aggregation (kwargs )
1259
+ assert func is not None
1259
1260
1260
1261
return relabeling , func , columns , order
1261
1262
0 commit comments