Skip to content

Commit

Permalink
Merge pull request numba#8909 from stuartarchibald/fix/8903
Browse files Browse the repository at this point in the history
Fix numba#8903. `NumbaDeprecationWarning`s raised from `@{gu,}vectorize`.
  • Loading branch information
sklam committed Apr 25, 2023
1 parent 76a1ea0 commit b470474
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 27 deletions.
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

0 comments on commit b470474

Please sign in to comment.