diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-06-08 16:35:31 -0700 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-06-15 11:42:02 -0700 |
commit | 974c865219223742a07375bea1f6da246e3326ef (patch) | |
tree | 6dc23964217131da259b9976ed4ad78f821e66a6 | |
parent | dc541a8565da9f14f30a3424ae93259b514f8997 (diff) | |
download | numpy-974c865219223742a07375bea1f6da246e3326ef.tar.gz |
API: Add leading underscore to `no_nep50_warning` and `get/set_promotion_state`
-rw-r--r-- | numpy/__init__.py | 2 | ||||
-rw-r--r-- | numpy/__init__.pyi | 6 | ||||
-rw-r--r-- | numpy/core/_methods.py | 8 | ||||
-rw-r--r-- | numpy/core/_ufunc_config.py | 6 | ||||
-rw-r--r-- | numpy/core/multiarray.py | 7 | ||||
-rw-r--r-- | numpy/core/numeric.py | 8 | ||||
-rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 8 | ||||
-rw-r--r-- | numpy/core/src/multiarray/convert_datatype.h | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_einsum.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_half.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_scalarmath.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 2 | ||||
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 2 | ||||
-rw-r--r-- | numpy/testing/_private/utils.py | 10 |
17 files changed, 44 insertions, 43 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 966ae6801..51270a86a 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -409,7 +409,7 @@ else: # it is tidier organized. core.multiarray._multiarray_umath._reload_guard() - core.set_promotion_state(os.environ.get("NPY_PROMOTION_STATE", "legacy")) + core._set_promotion_state(os.environ.get("NPY_PROMOTION_STATE", "legacy")) # Tell PyInstaller where to find hook-numpy.py def _pyinstaller_hooks_dir(): diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 31e84f016..12701251c 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -3354,9 +3354,9 @@ class errstate(Generic[_CallType], ContextDecorator): ) -> None: ... @contextmanager -def no_nep50_warning() -> Generator[None, None, None]: ... -def get_promotion_state() -> str: ... -def set_promotion_state(state: str, /) -> None: ... +def _no_nep50_warning() -> Generator[None, None, None]: ... +def _get_promotion_state() -> str: ... +def _set_promotion_state(state: str, /) -> None: ... class ndenumerate(Generic[_ScalarType]): iter: flatiter[NDArray[_ScalarType]] diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index 4ed271902..040f02a9d 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -11,7 +11,7 @@ from numpy.core import umath as um from numpy.core.multiarray import asanyarray from numpy.core import numerictypes as nt from numpy.core import _exceptions -from numpy.core._ufunc_config import no_nep50_warning +from numpy.core._ufunc_config import _no_nep50_warning from numpy._globals import _NoValue from numpy.compat import pickle, os_fspath @@ -180,7 +180,7 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True): ret = umr_sum(arr, axis, dtype, out, keepdims, where=where) if isinstance(ret, mu.ndarray): - with no_nep50_warning(): + with _no_nep50_warning(): ret = um.true_divide( ret, rcount, out=ret, casting='unsafe', subok=False) if is_float16_result and out is None: @@ -222,7 +222,7 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, # matching rcount to arrmean when where is specified as array div = rcount.reshape(arrmean.shape) if isinstance(arrmean, mu.ndarray): - with no_nep50_warning(): + with _no_nep50_warning(): arrmean = um.true_divide(arrmean, div, out=arrmean, casting='unsafe', subok=False) elif hasattr(arrmean, "dtype"): @@ -254,7 +254,7 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, # divide by degrees of freedom if isinstance(ret, mu.ndarray): - with no_nep50_warning(): + with _no_nep50_warning(): ret = um.true_divide( ret, rcount, out=ret, casting='unsafe', subok=False) elif hasattr(ret, 'dtype'): diff --git a/numpy/core/_ufunc_config.py b/numpy/core/_ufunc_config.py index 1937c4ca2..eb69b9c34 100644 --- a/numpy/core/_ufunc_config.py +++ b/numpy/core/_ufunc_config.py @@ -17,7 +17,7 @@ from . import umath __all__ = [ "seterr", "geterr", "setbufsize", "getbufsize", "seterrcall", "geterrcall", - "errstate", 'no_nep50_warning' + "errstate", '_no_nep50_warning' ] _errdict = {"ignore": ERR_IGNORE, @@ -447,11 +447,11 @@ def _setdef(): _setdef() -NO_NEP50_WARNING = contextvars.ContextVar("no_nep50_warning", default=False) +NO_NEP50_WARNING = contextvars.ContextVar("_no_nep50_warning", default=False) @set_module('numpy') @contextlib.contextmanager -def no_nep50_warning(): +def _no_nep50_warning(): """ Context manager to disable NEP 50 warnings. This context manager is only relevant if the NEP 50 warnings are enabled globally (which is NOT diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index e8ac27987..65b7cb46d 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -17,6 +17,7 @@ from ._multiarray_umath import ( _fastCopyAndTranspose, _flagdict, from_dlpack, _insert, _reconstruct, _vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version, _get_madvise_hugepage, _set_madvise_hugepage, + _get_promotion_state, _set_promotion_state, ) __all__ = [ @@ -41,7 +42,7 @@ __all__ = [ 'set_legacy_print_mode', 'set_numeric_ops', 'set_string_function', 'set_typeDict', 'shares_memory', 'tracemalloc_domain', 'typeinfo', 'unpackbits', 'unravel_index', 'vdot', 'where', 'zeros', - 'get_promotion_state', 'set_promotion_state'] + '_get_promotion_state', '_set_promotion_state'] # For backward compatibility, make sure pickle imports these functions from here _reconstruct.__module__ = 'numpy.core.multiarray' @@ -69,8 +70,8 @@ promote_types.__module__ = 'numpy' set_numeric_ops.__module__ = 'numpy' seterrobj.__module__ = 'numpy' zeros.__module__ = 'numpy' -get_promotion_state.__module__ = 'numpy' -set_promotion_state.__module__ = 'numpy' +_get_promotion_state.__module__ = 'numpy' +_set_promotion_state.__module__ = 'numpy' # We can't verify dispatcher signatures because NumPy's C functions don't diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index f81cfebce..d6e1d4eec 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -17,7 +17,7 @@ from .multiarray import ( fromstring, inner, lexsort, matmul, may_share_memory, min_scalar_type, ndarray, nditer, nested_iters, promote_types, putmask, result_type, set_numeric_ops, shares_memory, vdot, where, - zeros, normalize_axis_index, get_promotion_state, set_promotion_state) + zeros, normalize_axis_index, _get_promotion_state, _set_promotion_state) from . import overrides from . import umath @@ -27,7 +27,7 @@ from .umath import (multiply, invert, sin, PINF, NAN) from . import numerictypes from .numerictypes import longlong, intc, int_, float_, complex_, bool_ from ._exceptions import TooHardError, AxisError -from ._ufunc_config import errstate, no_nep50_warning +from ._ufunc_config import errstate, _no_nep50_warning bitwise_not = invert ufunc = type(sin) @@ -55,7 +55,7 @@ __all__ = [ 'BUFSIZE', 'ALLOW_THREADS', 'ComplexWarning', 'full', 'full_like', 'matmul', 'shares_memory', 'may_share_memory', 'MAY_SHARE_BOUNDS', 'MAY_SHARE_EXACT', 'TooHardError', 'AxisError', - 'get_promotion_state', 'set_promotion_state'] + '_get_promotion_state', '_set_promotion_state'] @set_module('numpy') @@ -2353,7 +2353,7 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): array([False, True]) """ def within_tol(x, y, atol, rtol): - with errstate(invalid='ignore'), no_nep50_warning(): + with errstate(invalid='ignore'), _no_nep50_warning(): return less_equal(abs(x-y), atol + rtol * abs(y)) x = asanyarray(a) diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c index 0458b1281..be136ab59 100644 --- a/numpy/core/src/multiarray/convert_datatype.c +++ b/numpy/core/src/multiarray/convert_datatype.c @@ -93,7 +93,7 @@ npy_give_promotion_warnings(void) NPY_NO_EXPORT PyObject * -npy_get_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(arg)) { +npy__get_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(arg)) { if (npy_promotion_state == NPY_USE_WEAK_PROMOTION) { return PyUnicode_FromString("weak"); } @@ -109,11 +109,11 @@ npy_get_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(arg)) { NPY_NO_EXPORT PyObject * -npy_set_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *arg) +npy__set_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *arg) { if (!PyUnicode_Check(arg)) { PyErr_SetString(PyExc_TypeError, - "set_promotion_state() argument or NPY_PROMOTION_STATE " + "_set_promotion_state() argument or NPY_PROMOTION_STATE " "must be a string."); return NULL; } @@ -128,7 +128,7 @@ npy_set_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *arg) } else { PyErr_Format(PyExc_TypeError, - "set_promotion_state() argument or NPY_PROMOTION_STATE must be " + "_set_promotion_state() argument or NPY_PROMOTION_STATE must be " "'weak', 'legacy', or 'weak_and_warn' but got '%.100S'", arg); return NULL; } diff --git a/numpy/core/src/multiarray/convert_datatype.h b/numpy/core/src/multiarray/convert_datatype.h index 2d99042f2..1a2f91337 100644 --- a/numpy/core/src/multiarray/convert_datatype.h +++ b/numpy/core/src/multiarray/convert_datatype.h @@ -19,10 +19,10 @@ NPY_NO_EXPORT int npy_give_promotion_warnings(void); NPY_NO_EXPORT PyObject * -npy_get_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(arg)); +npy__get_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(arg)); NPY_NO_EXPORT PyObject * -npy_set_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *arg); +npy__set_promotion_state(PyObject *NPY_UNUSED(mod), PyObject *arg); NPY_NO_EXPORT PyObject * PyArray_GetCastingImpl(PyArray_DTypeMeta *from, PyArray_DTypeMeta *to); diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 0db64d4c0..10114ce8b 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4503,14 +4503,14 @@ static struct PyMethodDef array_module_methods[] = { {"get_handler_version", (PyCFunction) get_handler_version, METH_VARARGS, NULL}, - {"get_promotion_state", - (PyCFunction)npy_get_promotion_state, + {"_get_promotion_state", + (PyCFunction)npy__get_promotion_state, METH_NOARGS, "Get the current NEP 50 promotion state."}, - {"set_promotion_state", - (PyCFunction)npy_set_promotion_state, + {"_set_promotion_state", + (PyCFunction)npy__set_promotion_state, METH_O, "Set the NEP 50 promotion state. This is not thread-safe.\n" "The optional warnings can be safely silenced using the \n" - "`np.no_nep50_warning()` context manager."}, + "`np._no_nep50_warning()` context manager."}, {"_add_newdoc_ufunc", (PyCFunction)add_newdoc_ufunc, METH_VARARGS, NULL}, {"_get_sfloat_dtype", diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index ce6b9c9d4..637c2c141 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -1288,7 +1288,7 @@ class TestPromotion: """Test cases related to more complex DType promotions. Further promotion tests are defined in `test_numeric.py` """ - @np.no_nep50_warning() + @np._no_nep50_warning() @pytest.mark.parametrize(["other", "expected"], [(2**16-1, np.complex64), (2**32-1, np.complex128 if OLD_PROMOTION else np.complex64), @@ -1363,7 +1363,7 @@ class TestPromotion: @pytest.mark.parametrize(["other", "expected"], [(1, rational), (1., np.float64)]) - @np.no_nep50_warning() + @np._no_nep50_warning() def test_float_int_pyscalar_promote_rational(self, other, expected): # Note that rationals are a bit akward as they promote with float64 # or default ints, but not float16 or uint8/int8 (which looks diff --git a/numpy/core/tests/test_einsum.py b/numpy/core/tests/test_einsum.py index 05ef124d0..ea96f0fef 100644 --- a/numpy/core/tests/test_einsum.py +++ b/numpy/core/tests/test_einsum.py @@ -239,7 +239,7 @@ class TestEinsum: assert_(b.base is a) assert_equal(b, a.swapaxes(0, 1)) - @np.no_nep50_warning() + @np._no_nep50_warning() def check_einsum_sums(self, dtype, do_opt=False): # Check various sums. Does many sizes to exercise unrolled loops. diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py index b93b9158e..d554943a5 100644 --- a/numpy/core/tests/test_half.py +++ b/numpy/core/tests/test_half.py @@ -85,7 +85,7 @@ class TestHalf: @pytest.mark.parametrize("offset", [None, "up", "down"]) @pytest.mark.parametrize("shift", [None, "up", "down"]) @pytest.mark.parametrize("float_t", [np.float32, np.float64]) - @np.no_nep50_warning() + @np._no_nep50_warning() def test_half_conversion_rounding(self, float_t, shift, offset): # Assumes that round to even is used during casting. max_pattern = np.float16(np.finfo(np.float16).max).view(np.uint16) @@ -451,7 +451,7 @@ class TestHalf: assert_equal(np.frexp(b), ([-0.5, 0.625, 0.5, 0.5, 0.75], [2, 3, 1, 3, 2])) assert_equal(np.ldexp(b, [0, 1, 2, 4, 2]), [-2, 10, 4, 64, 12]) - @np.no_nep50_warning() + @np._no_nep50_warning() def test_half_coercion(self): """Test that half gets coerced properly with the other types""" a16 = np.array((1,), dtype=float16) diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py index d3ea2871a..431f2a06a 100644 --- a/numpy/core/tests/test_scalarmath.py +++ b/numpy/core/tests/test_scalarmath.py @@ -998,7 +998,7 @@ def test_longdouble_complex(): @pytest.mark.parametrize(["__op__", "__rop__", "op", "cmp"], ops_with_names) @pytest.mark.parametrize("subtype", [float, int, complex, np.float16]) -@np.no_nep50_warning() +@np._no_nep50_warning() def test_pyscalar_subclasses(subtype, __op__, __rop__, op, cmp): def op_func(self, other): return __op__ diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 11ae48042..e4b1ceee3 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -2402,7 +2402,7 @@ def test_ufunc_types(ufunc): @pytest.mark.parametrize('ufunc', [getattr(np, x) for x in dir(np) if isinstance(getattr(np, x), np.ufunc)]) -@np.no_nep50_warning() +@np._no_nep50_warning() def test_ufunc_noncontiguous(ufunc): ''' Check that contiguous and non-contiguous calls to ufuncs diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index b6ea12158..64318255b 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2981,7 +2981,7 @@ class TestPercentile: input_dtype, expected_dtype): expected_dtype = np.dtype(expected_dtype) - if np.get_promotion_state() == "legacy": + if np._get_promotion_state() == "legacy": expected_dtype = np.promote_types(expected_dtype, np.float64) arr = np.asarray([15.0, 20.0, 35.0, 40.0, 50.0], dtype=input_dtype) diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index 39eb10b92..f871a5f8e 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -1803,7 +1803,7 @@ class TestCholesky: c = np.linalg.cholesky(a) b = np.matmul(c, c.transpose(t).conj()) - with np.no_nep50_warning(): + with np._no_nep50_warning(): atol = 500 * a.shape[0] * np.finfo(dtype).eps assert_allclose(b, a, atol=atol, err_msg=f'{shape} {dtype}\n{a}\n{c}') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 73ff88737..4ec42cbb8 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -53,7 +53,7 @@ IS_PYSTON = hasattr(sys, "pyston_version_info") HAS_REFCOUNT = getattr(sys, 'getrefcount', None) is not None and not IS_PYSTON HAS_LAPACK64 = numpy.linalg.lapack_lite._ilp64 -OLD_PROMOTION = np.get_promotion_state() == 'legacy' +OLD_PROMOTION = np._get_promotion_state() == 'legacy' def import_nose(): @@ -476,7 +476,7 @@ def print_assert_equal(test_string, actual, desired): raise AssertionError(msg.getvalue()) -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired @@ -603,7 +603,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): raise AssertionError(_build_err_msg()) -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to significant @@ -703,7 +703,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): raise AssertionError(msg) -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True): __tracebackhide__ = True # Hide traceback for py.test @@ -941,7 +941,7 @@ def assert_array_equal(x, y, err_msg='', verbose=True): verbose=verbose, header='Arrays are not equal') -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired |