summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/multiarray.pyi5
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c9
-rw-r--r--numpy/core/src/multiarray/methods.c3
-rw-r--r--numpy/core/tests/test_api.py10
-rw-r--r--numpy/core/tests/test_multiarray.py26
5 files changed, 30 insertions, 23 deletions
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
index b02f7f391..8c4526a5d 100644
--- a/numpy/core/multiarray.pyi
+++ b/numpy/core/multiarray.pyi
@@ -20,7 +20,6 @@ from typing import (
from numpy import (
# Re-exports
- CopyMode,
busdaycalendar as busdaycalendar,
broadcast as broadcast,
dtype as dtype,
@@ -79,6 +78,10 @@ from numpy.typing import (
_TD64Like_co,
)
+from numpy.array_api import (
+ CopyMode
+)
+
if sys.version_info >= (3, 8):
from typing import SupportsIndex, final, Final, Literal as L
else:
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index a1f3dafb8..7aa1e9abe 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -169,13 +169,15 @@ PyArray_CopyConverter(PyObject *obj, PyArray_CopyMode *copymode) {
if (obj == Py_None) {
PyErr_SetString(PyExc_ValueError,
"NoneType copy mode not allowed. Please choose one of "
- "np.CopyMode.ALWAYS, np.CopyMode.IF_NEEDED, np.CopyMode.NEVER.");
+ "np.array_api.CopyMode.ALWAYS, "
+ "np.array_api.CopyMode.IF_NEEDED, "
+ "np.array_api.CopyMode.NEVER.");
return NPY_FAIL;
}
int int_copymode = -1;
PyObject* numpy_CopyMode = NULL;
- npy_cache_import("numpy._globals", "CopyMode", &numpy_CopyMode);
+ npy_cache_import("numpy.array_api", "CopyMode", &numpy_CopyMode);
if (numpy_CopyMode != NULL && PyObject_IsInstance(obj, numpy_CopyMode)) {
PyObject* mode_value = PyObject_GetAttrString(obj, "value");
@@ -198,7 +200,8 @@ PyArray_CopyConverter(PyObject *obj, PyArray_CopyMode *copymode) {
int_copymode != NPY_COPY_NEVER ) {
PyErr_Format(PyExc_ValueError,
"Unrecognized copy mode %d. Please choose one of "
- "np.CopyMode.ALWAYS, np.CopyMode.IF_NEEDED, np.CopyMode.NEVER, "
+ "np.array_api.CopyMode.ALWAYS, np.array_api.CopyMode.IF_NEEDED, "
+ "np.array_api.CopyMode.NEVER, "
"True/np.True_, False/np.False_", int_copymode);
return NPY_FAIL;
}
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index f20082c40..3e66e55f3 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -874,7 +874,8 @@ array_astype(PyArrayObject *self,
if( forcecopy == NPY_COPY_NEVER ) {
PyErr_SetString(PyExc_ValueError,
- "Unable to avoid copy while casting in np.CopyMode.NEVER");
+ "Unable to avoid copy while casting in "
+ "np.array_api.CopyMode.NEVER");
Py_DECREF(dtype);
return NULL;
}
diff --git a/numpy/core/tests/test_api.py b/numpy/core/tests/test_api.py
index d48b20800..e3e07138d 100644
--- a/numpy/core/tests/test_api.py
+++ b/numpy/core/tests/test_api.py
@@ -605,22 +605,22 @@ def test_astype_copyflag():
res_true = arr.astype(np.intp, copy=True)
assert not np.may_share_memory(arr, res_true)
- res_always = arr.astype(np.intp, copy=np.CopyMode.ALWAYS)
+ res_always = arr.astype(np.intp, copy=np.array_api.CopyMode.ALWAYS)
assert not np.may_share_memory(arr, res_always)
res_false = arr.astype(np.intp, copy=False)
# `res_false is arr` currently, but check `may_share_memory`.
assert np.may_share_memory(arr, res_false)
- res_if_needed = arr.astype(np.intp, copy=np.CopyMode.IF_NEEDED)
+ res_if_needed = arr.astype(np.intp, copy=np.array_api.CopyMode.IF_NEEDED)
# `res_if_needed is arr` currently, but check `may_share_memory`.
assert np.may_share_memory(arr, res_if_needed)
- res_never = arr.astype(np.intp, copy=np.CopyMode.NEVER)
+ res_never = arr.astype(np.intp, copy=np.array_api.CopyMode.NEVER)
assert np.may_share_memory(arr, res_never)
# Simple tests for when a copy is necessary:
res_false = arr.astype(np.float64, copy=False)
assert_array_equal(res_false, arr)
- res_if_needed = arr.astype(np.float64, copy=np.CopyMode.IF_NEEDED)
+ res_if_needed = arr.astype(np.float64, copy=np.array_api.CopyMode.IF_NEEDED)
assert_array_equal(res_if_needed, arr)
- assert_raises(ValueError, arr.astype, np.float64, copy=np.CopyMode.NEVER)
+ assert_raises(ValueError, arr.astype, np.float64, copy=np.array_api.CopyMode.NEVER)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index b9dbda43b..c51d2766e 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -7818,8 +7818,8 @@ class TestNewBufferProtocol:
class TestArrayCreationCopyArgument(object):
- true_vals = [True, np.CopyMode.ALWAYS, np.True_]
- false_vals = [False, np.CopyMode.IF_NEEDED, np.False_]
+ true_vals = [True, np.array_api.CopyMode.ALWAYS, np.True_]
+ false_vals = [False, np.array_api.CopyMode.IF_NEEDED, np.False_]
def test_scalars(self):
# Test both numpy and python scalars
@@ -7830,9 +7830,9 @@ class TestArrayCreationCopyArgument(object):
# Test never-copy raises error:
assert_raises(ValueError, np.array, scalar,
- copy=np.CopyMode.NEVER)
+ copy=np.array_api.CopyMode.NEVER)
assert_raises(ValueError, np.array, pyscalar,
- copy=np.CopyMode.NEVER)
+ copy=np.array_api.CopyMode.NEVER)
def test_compatible_cast(self):
@@ -7861,7 +7861,7 @@ class TestArrayCreationCopyArgument(object):
res = np.array(arr, copy=copy, dtype=int2)
assert res is arr or res.base is arr
- res = np.array(arr, copy=np.CopyMode.NEVER, dtype=int2)
+ res = np.array(arr, copy=np.array_api.CopyMode.NEVER, dtype=int2)
assert res is arr or res.base is arr
else:
@@ -7872,7 +7872,7 @@ class TestArrayCreationCopyArgument(object):
assert_array_equal(res, arr)
assert_raises(ValueError, np.array,
- arr, copy=np.CopyMode.NEVER, dtype=int2)
+ arr, copy=np.array_api.CopyMode.NEVER, dtype=int2)
def test_buffer_interface(self):
@@ -7888,7 +7888,7 @@ class TestArrayCreationCopyArgument(object):
for copy in self.false_vals:
res = np.array(view, copy=copy)
assert np.may_share_memory(arr, res)
- res = np.array(view, copy=np.CopyMode.NEVER)
+ res = np.array(view, copy=np.array_api.CopyMode.NEVER)
assert np.may_share_memory(arr, res)
def test_array_interfaces(self):
@@ -7900,9 +7900,9 @@ class TestArrayCreationCopyArgument(object):
arr = ArrayLike()
- for copy, val in [(True, None), (np.CopyMode.ALWAYS, None),
- (False, arr), (np.CopyMode.IF_NEEDED, arr),
- (np.CopyMode.NEVER, arr)]:
+ for copy, val in [(True, None), (np.array_api.CopyMode.ALWAYS, None),
+ (False, arr), (np.array_api.CopyMode.IF_NEEDED, arr),
+ (np.array_api.CopyMode.NEVER, arr)]:
res = np.array(arr, copy=copy)
assert res.base is val
@@ -7930,7 +7930,7 @@ class TestArrayCreationCopyArgument(object):
assert_array_equal(res, base_arr)
assert res is base_arr # numpy trusts the ArrayLike
- assert np.array(arr, copy=np.CopyMode.NEVER) is base_arr
+ assert np.array(arr, copy=np.array_api.CopyMode.NEVER) is base_arr
@pytest.mark.parametrize(
"arr", [np.ones(()), np.arange(81).reshape((9, 9))])
@@ -7976,7 +7976,7 @@ class TestArrayCreationCopyArgument(object):
if not IS_PYPY:
assert res is arr or res.base.obj is arr
- res = np.array(view, copy=np.CopyMode.NEVER, order=order2)
+ res = np.array(view, copy=np.array_api.CopyMode.NEVER, order=order2)
if not IS_PYPY:
assert res is arr or res.base.obj is arr
else:
@@ -7984,7 +7984,7 @@ class TestArrayCreationCopyArgument(object):
res = np.array(arr, copy=copy, order=order2)
assert_array_equal(arr, res)
assert_raises(ValueError, np.array,
- view, copy=np.CopyMode.NEVER, order=order2)
+ view, copy=np.array_api.CopyMode.NEVER, order=order2)
class TestArrayAttributeDeletion: