summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/multiarray.pyi14
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c12
-rw-r--r--numpy/core/src/multiarray/methods.c2
-rw-r--r--numpy/core/tests/test_api.py10
-rw-r--r--numpy/core/tests/test_multiarray.py26
5 files changed, 32 insertions, 32 deletions
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
index 8c4526a5d..7ae831b53 100644
--- a/numpy/core/multiarray.pyi
+++ b/numpy/core/multiarray.pyi
@@ -79,7 +79,7 @@ from numpy.typing import (
)
from numpy.array_api import (
- CopyMode
+ _CopyMode
)
if sys.version_info >= (3, 8):
@@ -181,7 +181,7 @@ def array(
object: _ArrayType,
dtype: None = ...,
*,
- copy: bool | CopyMode = ...,
+ copy: bool | _CopyMode = ...,
order: _OrderKACF = ...,
subok: L[True],
ndmin: int = ...,
@@ -192,7 +192,7 @@ def array(
object: _ArrayLike[_SCT],
dtype: None = ...,
*,
- copy: bool | CopyMode = ...,
+ copy: bool | _CopyMode = ...,
order: _OrderKACF = ...,
subok: bool = ...,
ndmin: int = ...,
@@ -203,7 +203,7 @@ def array(
object: object,
dtype: None = ...,
*,
- copy: bool | CopyMode = ...,
+ copy: bool | _CopyMode = ...,
order: _OrderKACF = ...,
subok: bool = ...,
ndmin: int = ...,
@@ -214,7 +214,7 @@ def array(
object: Any,
dtype: _DTypeLike[_SCT],
*,
- copy: bool | CopyMode = ...,
+ copy: bool | _CopyMode = ...,
order: _OrderKACF = ...,
subok: bool = ...,
ndmin: int = ...,
@@ -225,7 +225,7 @@ def array(
object: Any,
dtype: DTypeLike,
*,
- copy: bool | CopyMode = ...,
+ copy: bool | _CopyMode = ...,
order: _OrderKACF = ...,
subok: bool = ...,
ndmin: int = ...,
@@ -1005,7 +1005,7 @@ class flagsobj:
def __getitem__(self, key: _GetItemKeys) -> bool: ...
def __setitem__(self, key: _SetItemKeys, value: bool) -> None: ...
-class CopyMode(enum.Enum):
+class _CopyMode(enum.Enum):
ALWAYS: L[1]
IF_NEEDED: L[0]
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index 7aa1e9abe..15fe4bde2 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -169,15 +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.array_api.CopyMode.ALWAYS, "
- "np.array_api.CopyMode.IF_NEEDED, "
- "np.array_api.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.array_api", "CopyMode", &numpy_CopyMode);
+ npy_cache_import("numpy", "_CopyMode", &numpy_CopyMode);
if (numpy_CopyMode != NULL && PyObject_IsInstance(obj, numpy_CopyMode)) {
PyObject* mode_value = PyObject_GetAttrString(obj, "value");
@@ -200,8 +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.array_api.CopyMode.ALWAYS, np.array_api.CopyMode.IF_NEEDED, "
- "np.array_api.CopyMode.NEVER, "
+ "np._CopyMode.ALWAYS, np._CopyMode.IF_NEEDED, "
+ "np._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 3e66e55f3..ffa735b38 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -875,7 +875,7 @@ array_astype(PyArrayObject *self,
if( forcecopy == NPY_COPY_NEVER ) {
PyErr_SetString(PyExc_ValueError,
"Unable to avoid copy while casting in "
- "np.array_api.CopyMode.NEVER");
+ "np._CopyMode.NEVER");
Py_DECREF(dtype);
return NULL;
}
diff --git a/numpy/core/tests/test_api.py b/numpy/core/tests/test_api.py
index ea2bc8e3d..d3c7211cd 100644
--- a/numpy/core/tests/test_api.py
+++ b/numpy/core/tests/test_api.py
@@ -605,24 +605,24 @@ 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.array_api.CopyMode.ALWAYS)
+ res_always = arr.astype(np.intp, copy=np._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.array_api.CopyMode.IF_NEEDED)
+ res_if_needed = arr.astype(np.intp, copy=np._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.array_api.CopyMode.NEVER)
+ res_never = arr.astype(np.intp, copy=np._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.array_api.CopyMode.IF_NEEDED)
+ copy=np._CopyMode.IF_NEEDED)
assert_array_equal(res_if_needed, arr)
assert_raises(ValueError, arr.astype, np.float64,
- copy=np.array_api.CopyMode.NEVER)
+ copy=np._CopyMode.NEVER)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 9621b700c..9c56df2ba 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.array_api.CopyMode.ALWAYS, np.True_]
- false_vals = [False, np.array_api.CopyMode.IF_NEEDED, np.False_]
+ true_vals = [True, np._CopyMode.ALWAYS, np.True_]
+ false_vals = [False, np._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.array_api.CopyMode.NEVER)
+ copy=np._CopyMode.NEVER)
assert_raises(ValueError, np.array, pyscalar,
- copy=np.array_api.CopyMode.NEVER)
+ copy=np._CopyMode.NEVER)
def test_compatible_cast(self):
@@ -7862,7 +7862,7 @@ class TestArrayCreationCopyArgument(object):
assert res is arr or res.base is arr
res = np.array(arr,
- copy=np.array_api.CopyMode.NEVER,
+ copy=np._CopyMode.NEVER,
dtype=int2)
assert res is arr or res.base is arr
@@ -7874,7 +7874,7 @@ class TestArrayCreationCopyArgument(object):
assert_array_equal(res, arr)
assert_raises(ValueError, np.array,
- arr, copy=np.array_api.CopyMode.NEVER,
+ arr, copy=np._CopyMode.NEVER,
dtype=int2)
def test_buffer_interface(self):
@@ -7891,7 +7891,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.array_api.CopyMode.NEVER)
+ res = np.array(view, copy=np._CopyMode.NEVER)
assert np.may_share_memory(arr, res)
def test_array_interfaces(self):
@@ -7903,9 +7903,9 @@ class TestArrayCreationCopyArgument(object):
arr = ArrayLike()
- 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)]:
+ for copy, val in [(True, None), (np._CopyMode.ALWAYS, None),
+ (False, arr), (np._CopyMode.IF_NEEDED, arr),
+ (np._CopyMode.NEVER, arr)]:
res = np.array(arr, copy=copy)
assert res.base is val
@@ -7933,7 +7933,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.array_api.CopyMode.NEVER) is base_arr
+ assert np.array(arr, copy=np._CopyMode.NEVER) is base_arr
@pytest.mark.parametrize(
"arr", [np.ones(()), np.arange(81).reshape((9, 9))])
@@ -7979,7 +7979,7 @@ class TestArrayCreationCopyArgument(object):
if not IS_PYPY:
assert res is arr or res.base.obj is arr
- res = np.array(view, copy=np.array_api.CopyMode.NEVER,
+ res = np.array(view, copy=np._CopyMode.NEVER,
order=order2)
if not IS_PYPY:
assert res is arr or res.base.obj is arr
@@ -7988,7 +7988,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.array_api.CopyMode.NEVER,
+ view, copy=np._CopyMode.NEVER,
order=order2)