-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: numba engine in df.apply #54666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a6add5c
ENH: numba engine in df.apply
lithomas1 cca4656
fixes
lithomas1 83d4598
more fixes
lithomas1 81e85cc
try to fix
lithomas1 c249a2c
Merge branch 'main' into numba-raw-apply
lithomas1 839a6d9
Merge branch 'main' into numba-raw-apply
lithomas1 5da0723
address code review
lithomas1 dae9a15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dc5a734
go for green
lithomas1 8504f45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4fbd6ae
update type
lithomas1 9465038
Merge branch 'main' into numba-raw-apply
lithomas1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9919,6 +9919,8 @@ def apply( | |
result_type: Literal["expand", "reduce", "broadcast"] | None = None, | ||
args=(), | ||
by_row: Literal[False, "compat"] = "compat", | ||
engine: str = "python", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you type as a |
||
engine_kwargs: dict = {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we usually default this as |
||
**kwargs, | ||
): | ||
""" | ||
|
@@ -9978,6 +9980,26 @@ def apply( | |
If False, the funcs will be passed the whole Series at once. | ||
|
||
.. versionadded:: 2.1.0 | ||
|
||
engine : {'python', 'numba'}, default 'python' | ||
Choose between the python (default) engine or the numba engine in apply. | ||
|
||
The numba engine will attempt to JIT compile the passed function, | ||
which may result in speedups for large DataFrames. | ||
It also supports the following engine_kwargs : | ||
|
||
- nopython (compile the function in nopython mode) | ||
- nogil (release the GIL inside the JIT compiled function) | ||
- parallel (try to apply the function in parallel over the DataFrame) | ||
|
||
As of right now, the numba engine can only be used with raw=True. | ||
|
||
.. versionadded:: 2.2.0 | ||
|
||
engine_kwargs : dict | ||
Pass keyword arguments to the engine. | ||
This is currently only used by the numba engine, | ||
see the documentation for the engine argument for more information. | ||
**kwargs | ||
Additional keyword arguments to pass as keywords arguments to | ||
`func`. | ||
|
@@ -10078,6 +10100,8 @@ def apply( | |
raw=raw, | ||
result_type=result_type, | ||
by_row=by_row, | ||
engine=engine, | ||
engine_kwargs=engine_kwargs, | ||
args=args, | ||
kwargs=kwargs, | ||
) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is inferring the shape from the first element similar to what we do for
DataFrame.apply
?It would be good to note what type of UDFs are supported in the engine docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.apply_along_axis
, which we use does this.see https://github.com/numpy/numpy/blob/d676a1fe2d495f9d8a86103644bed141c2e69787/numpy/lib/_shape_base_impl.py#L373-L380.
I'll add a note linking to numba's supported Python/numpy features.