@@ -209,6 +209,30 @@ def apply(
209
209
"""
210
210
Apply `func` along the given axis using Numba.
211
211
"""
212
+
213
+ if is_list_like (func ):
214
+ raise NotImplementedError (
215
+ "the 'numba' engine doesn't support lists of callables yet"
216
+ )
217
+
218
+ if isinstance (func , str ):
219
+ raise NotImplementedError (
220
+ "the 'numba' engine doesn't support using "
221
+ "a string as the callable function"
222
+ )
223
+
224
+ elif isinstance (func , np .ufunc ):
225
+ raise NotImplementedError (
226
+ "the 'numba' engine doesn't support "
227
+ "using a numpy ufunc as the callable function"
228
+ )
229
+
230
+ # check for data typing
231
+ if not isinstance (data , np .ndarray ):
232
+ if len (data .columns ) == 0 and len (data .index ) == 0 :
233
+ return data .copy () # mimic apply_empty_result()
234
+ return FrameApply .apply_standard ()
235
+
212
236
engine_kwargs : dict [str , bool ] | None = (
213
237
decorator if isinstance (decorator , dict ) else None
214
238
)
@@ -1011,10 +1035,6 @@ def apply(self) -> DataFrame | Series:
1011
1035
1012
1036
# dispatch to handle list-like or dict-like
1013
1037
if is_list_like (self .func ):
1014
- if self .engine == "numba" :
1015
- raise NotImplementedError (
1016
- "the 'numba' engine doesn't support lists of callables yet"
1017
- )
1018
1038
return self .apply_list_or_dict_like ()
1019
1039
1020
1040
# all empty
@@ -1023,31 +1043,17 @@ def apply(self) -> DataFrame | Series:
1023
1043
1024
1044
# string dispatch
1025
1045
if isinstance (self .func , str ):
1026
- if self .engine == "numba" :
1027
- raise NotImplementedError (
1028
- "the 'numba' engine doesn't support using "
1029
- "a string as the callable function"
1030
- )
1031
1046
return self .apply_str ()
1032
1047
1033
1048
# ufunc
1034
1049
elif isinstance (self .func , np .ufunc ):
1035
- if self .engine == "numba" :
1036
- raise NotImplementedError (
1037
- "the 'numba' engine doesn't support "
1038
- "using a numpy ufunc as the callable function"
1039
- )
1040
1050
with np .errstate (all = "ignore" ):
1041
1051
results = self .obj ._mgr .apply ("apply" , func = self .func )
1042
1052
# _constructor will retain self.index and self.columns
1043
1053
return self .obj ._constructor_from_mgr (results , axes = results .axes )
1044
1054
1045
1055
# broadcasting
1046
1056
if self .result_type == "broadcast" :
1047
- if self .engine == "numba" :
1048
- raise NotImplementedError (
1049
- "the 'numba' engine doesn't support result_type='broadcast'"
1050
- )
1051
1057
return self .apply_broadcast (self .obj )
1052
1058
1053
1059
# one axis empty
0 commit comments