Skip to content
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

Fix #8903. NumbaDeprecationWarnings raised from @{gu,}vectorize. #8909

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions numba/np/ufunc/dufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ class DUFunc(serialize.ReduceMixin, _internal._DUFunc):
def __init__(self, py_func, identity=None, cache=False, targetoptions={}):
if is_jitted(py_func):
py_func = py_func.py_func
dispatcher = jit(_target='npyufunc',
cache=cache,
**targetoptions)(py_func)
with ufuncbuilder._suppress_deprecation_warning_nopython_not_supplied():
dispatcher = jit(_target='npyufunc',
cache=cache,
**targetoptions)(py_func)
self._initialize(dispatcher, identity)
functools.update_wrapper(self, py_func)

Expand Down
26 changes: 22 additions & 4 deletions numba/np/ufunc/ufuncbuilder.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-

import inspect
import warnings
from contextlib import contextmanager

from numba.core import config, targetconfig
from numba.core.decorators import jit
from numba.core.descriptors import TargetDescriptor
from numba.core.extending import is_jitted
from numba.core.errors import NumbaDeprecationWarning
from numba.core.options import TargetOptions, include_default_options
from numba.core.registry import cpu_target
from numba.core.target_extension import dispatcher_registry, target_registry
Expand Down Expand Up @@ -230,6 +232,20 @@ def parse_identity(identity):
return identity


@contextmanager
def _suppress_deprecation_warning_nopython_not_supplied():
"""This suppresses the NumbaDeprecationWarning that occurs through the use
of `jit` without the `nopython` kwarg. This use of `jit` occurs in a few
places in the `{g,}ufunc` mechanism in Numba, predominantly to wrap the
"kernel" function."""
with warnings.catch_warnings():
warnings.filterwarnings('ignore',
category=NumbaDeprecationWarning,
message=(".*The 'nopython' keyword argument "
"was not supplied*"),)
yield


# Class definitions

class _BaseUFuncBuilder(object):
Expand Down Expand Up @@ -260,9 +276,10 @@ def __init__(self, py_func, identity=None, cache=False, targetoptions={}):
py_func = py_func.py_func
self.py_func = py_func
self.identity = parse_identity(identity)
self.nb_func = jit(_target='npyufunc',
cache=cache,
**targetoptions)(py_func)
with _suppress_deprecation_warning_nopython_not_supplied():
self.nb_func = jit(_target='npyufunc',
cache=cache,
**targetoptions)(py_func)
self._sigs = []
self._cres = {}

Expand Down Expand Up @@ -325,7 +342,8 @@ def __init__(self, py_func, signature, identity=None, cache=False,
targetoptions={}, writable_args=()):
self.py_func = py_func
self.identity = parse_identity(identity)
self.nb_func = jit(_target='npyufunc', cache=cache)(py_func)
with _suppress_deprecation_warning_nopython_not_supplied():
self.nb_func = jit(_target='npyufunc', cache=cache)(py_func)
self.signature = signature
self.sin, self.sout = parse_signature(signature)
self.targetoptions = targetoptions
Expand Down
2 changes: 1 addition & 1 deletion numba/tests/npyufunc/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_ufunc_exception_on_write_to_readonly(self):
tests = []
expect = "ufunc 'sin' called with an explicit output that is read-only"
tests.append((jit(nopython=True), TypingError, expect))
tests.append((jit(nopython=False), ValueError,
tests.append((jit(forceobj=True), ValueError,
"output array is read-only"))

for dec, exc, msg in tests:
Expand Down
2 changes: 1 addition & 1 deletion numba/tests/npyufunc/test_vectorize_decor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TestParallelVectorizeDecor(unittest.TestCase, BaseVectorizeDecor):

class TestCPUVectorizeJitted(unittest.TestCase, BaseVectorizeDecor):
target = 'cpu'
wrapper = jit
wrapper = jit(nopython=True)


class BaseVectorizeNopythonArg(unittest.TestCase, CheckWarningsMixin):
Expand Down
Loading