-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: Consolidate numba facilities #32770
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
jreback
merged 6 commits into
pandas-dev:master
from
mroeschke:groupby_transform_engine
Mar 19, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b8f5ae
Centralize numba checks and have groupby.transform accept engine and …
b551cdb
Merge remote-tracking branch 'upstream/master' into groupby_transform…
7ffb61e
Remove engine kwarg for now
b722731
isort
32312cc
Merge remote-tracking branch 'upstream/master' into groupby_transform…
d47a90d
Move numba_.py to core/util
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Common utilities for Numba operations""" | ||
import types | ||
from typing import Callable, Dict, Optional | ||
|
||
import numpy as np | ||
|
||
from pandas.compat._optional import import_optional_dependency | ||
|
||
|
||
def check_kwargs_and_nopython( | ||
kwargs: Optional[Dict] = None, nopython: Optional[bool] = None | ||
): | ||
if kwargs and nopython: | ||
raise ValueError( | ||
"numba does not support kwargs with nopython=True: " | ||
"https://github.com/numba/numba/issues/2916" | ||
) | ||
|
||
|
||
def get_jit_arguments(engine_kwargs: Optional[Dict[str, bool]] = None): | ||
""" | ||
Return arguments to pass to numba.JIT, falling back on pandas default JIT settings. | ||
""" | ||
if engine_kwargs is None: | ||
engine_kwargs = {} | ||
|
||
nopython = engine_kwargs.get("nopython", True) | ||
nogil = engine_kwargs.get("nogil", False) | ||
parallel = engine_kwargs.get("parallel", False) | ||
return nopython, nogil, parallel | ||
|
||
|
||
def jit_user_function(func: Callable, nopython: bool, nogil: bool, parallel: bool): | ||
""" | ||
JIT the user's function given the configurable arguments. | ||
""" | ||
numba = import_optional_dependency("numba") | ||
|
||
if isinstance(func, numba.targets.registry.CPUDispatcher): | ||
# Don't jit a user passed jitted function | ||
numba_func = func | ||
else: | ||
|
||
@numba.generated_jit(nopython=nopython, nogil=nogil, parallel=parallel) | ||
def numba_func(data, *_args): | ||
if getattr(np, func.__name__, False) is func or isinstance( | ||
func, types.BuiltinFunctionType | ||
): | ||
jf = func | ||
else: | ||
jf = numba.jit(func, nopython=nopython, nogil=nogil) | ||
|
||
def impl(data, *_args): | ||
return jf(data, *_args) | ||
|
||
return impl | ||
|
||
return numba_func |
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.
no strong opinion, but should this go in pandas.compat?