summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/reference/c-api/array.rst5
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h2
-rw-r--r--numpy/core/src/multiarray/_multiarray_tests.c.src4
-rw-r--r--numpy/core/src/multiarray/ctors.c8
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c2
-rw-r--r--numpy/core/tests/test_multiarray.py6
6 files changed, 19 insertions, 8 deletions
diff --git a/doc/source/reference/c-api/array.rst b/doc/source/reference/c-api/array.rst
index 60037af8a..bb4405825 100644
--- a/doc/source/reference/c-api/array.rst
+++ b/doc/source/reference/c-api/array.rst
@@ -456,6 +456,11 @@ From other objects
Make sure the returned array can be written to.
+ .. c:macro:: NPY_ARRAY_ENSURECOPY
+
+ Make sure a copy is made of *op*. If this flag is not
+ present, data is not copied if it can be avoided.
+
.. c:macro:: NPY_ARRAY_ENSUREARRAY
Make sure the result is a base-class ndarray. By
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 566eae357..cc3b7c006 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -938,7 +938,7 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
#define NPY_ARRAY_UPDATEIFCOPY 0x1000 /* Deprecated in 1.14 */
#define NPY_ARRAY_WRITEBACKIFCOPY 0x2000
-#define _NPY_ARRAY_ENSURENOCOPY 0x4000
+#define NPY_ARRAY_ENSURENOCOPY 0x4000
/*
* NOTE: there are also internal flags defined in multiarray/arrayobject.h,
diff --git a/numpy/core/src/multiarray/_multiarray_tests.c.src b/numpy/core/src/multiarray/_multiarray_tests.c.src
index f21a901c1..be3eab6d6 100644
--- a/numpy/core/src/multiarray/_multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/_multiarray_tests.c.src
@@ -2363,11 +2363,11 @@ run_intp_converter(PyObject* NPY_UNUSED(self), PyObject *args)
return tup;
}
-/* used to test _NPY_ARRAY_ENSURENOCOPY raises ValueError */
+/* used to test NPY_ARRAY_ENSURENOCOPY raises ValueError */
static PyObject*
npy_ensurenocopy(PyObject* NPY_UNUSED(self), PyObject* args)
{
- int flags = _NPY_ARRAY_ENSURENOCOPY;
+ int flags = NPY_ARRAY_ENSURENOCOPY;
if (!PyArray_CheckFromAny(args, NULL, 0, 0, flags, NULL)) {
return NULL;
}
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index a8f41f582..470b3b2f8 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1738,7 +1738,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
/* Create a new array and copy the data */
Py_INCREF(dtype); /* hold on in case of a subarray that is replaced */
- if( flags & _NPY_ARRAY_ENSURENOCOPY ) {
+ if( flags & NPY_ARRAY_ENSURENOCOPY ) {
PyErr_SetString(PyExc_ValueError,
"Unable to avoid copy while creating "
"an array from descriptor.");
@@ -1808,7 +1808,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
* NPY_ARRAY_FORCECAST,
* NPY_ARRAY_ENSUREARRAY,
* NPY_ARRAY_ELEMENTSTRIDES,
- * _NPY_ARRAY_ENSURENOCOPY
+ * NPY_ARRAY_ENSURENOCOPY
*
* or'd (|) together
*
@@ -1873,7 +1873,7 @@ PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,
if ((requires & NPY_ARRAY_ELEMENTSTRIDES) &&
!PyArray_ElementStrides(obj)) {
PyObject *ret;
- if( requires & _NPY_ARRAY_ENSURENOCOPY ) {
+ if( requires & NPY_ARRAY_ENSURENOCOPY ) {
PyErr_SetString(PyExc_ValueError,
"Unable to avoid copy while creating a new array.");
return NULL;
@@ -1953,7 +1953,7 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
if (copy) {
- if( flags & _NPY_ARRAY_ENSURENOCOPY ) {
+ if( flags & NPY_ARRAY_ENSURENOCOPY ) {
PyErr_SetString(PyExc_ValueError,
"Unable to avoid copy while creating "
"an array from given array.");
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index bf60314ad..15c2e3c10 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -1623,7 +1623,7 @@ _array_fromobject_generic(
if (copy == NPY_COPY_ALWAYS) {
flags = NPY_ARRAY_ENSURECOPY;
} else if( copy == NPY_COPY_NEVER ) {
- flags = _NPY_ARRAY_ENSURENOCOPY;
+ flags = NPY_ARRAY_ENSURENOCOPY;
}
if (order == NPY_CORDER) {
flags |= NPY_ARRAY_C_CONTIGUOUS;
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 50133798c..4ef58d904 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -8010,8 +8010,14 @@ class TestArrayCreationCopyArgument(object):
arr.T, copy=np._CopyMode.NEVER,
order='C')
assert_raises(ValueError, np.array,
+ arr.T, copy=np._CopyMode.NEVER,
+ order='C', dtype=np.int64)
+ assert_raises(ValueError, np.array,
arr, copy=np._CopyMode.NEVER,
order='F')
+ assert_raises(ValueError, np.array,
+ arr, copy=np._CopyMode.NEVER,
+ order='F', dtype=np.int64)
class TestArrayAttributeDeletion: