@@ -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 :
@@ -1199,7 +1199,7 @@ def transform(self):
1199
1199
1200
1200
def reconstruct_func (
1201
1201
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 ]:
1203
1203
"""
1204
1204
This is the internal function to reconstruct func given if there is relabeling
1205
1205
or not and also normalize the keyword to get new order of columns.
@@ -1254,6 +1254,7 @@ def reconstruct_func(
1254
1254
1255
1255
if relabeling :
1256
1256
func , columns , order = normalize_keyword_aggregation (kwargs )
1257
+ assert func is not None
1257
1258
1258
1259
return relabeling , func , columns , order
1259
1260
0 commit comments