Skip to content

Commit ed8dc7f

Browse files
committed
Moved checks from Apply.apply to NumbaExecutionEngine.apply
1 parent 221cf7c commit ed8dc7f

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

pandas/core/apply.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,30 @@ def apply(
209209
"""
210210
Apply `func` along the given axis using Numba.
211211
"""
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+
212236
engine_kwargs: dict[str, bool] | None = (
213237
decorator if isinstance(decorator, dict) else None
214238
)
@@ -1011,10 +1035,6 @@ def apply(self) -> DataFrame | Series:
10111035

10121036
# dispatch to handle list-like or dict-like
10131037
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-
)
10181038
return self.apply_list_or_dict_like()
10191039

10201040
# all empty
@@ -1023,31 +1043,17 @@ def apply(self) -> DataFrame | Series:
10231043

10241044
# string dispatch
10251045
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-
)
10311046
return self.apply_str()
10321047

10331048
# ufunc
10341049
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-
)
10401050
with np.errstate(all="ignore"):
10411051
results = self.obj._mgr.apply("apply", func=self.func)
10421052
# _constructor will retain self.index and self.columns
10431053
return self.obj._constructor_from_mgr(results, axes=results.axes)
10441054

10451055
# broadcasting
10461056
if self.result_type == "broadcast":
1047-
if self.engine == "numba":
1048-
raise NotImplementedError(
1049-
"the 'numba' engine doesn't support result_type='broadcast'"
1050-
)
10511057
return self.apply_broadcast(self.obj)
10521058

10531059
# one axis empty

0 commit comments

Comments
 (0)