diff options
| author | Matti Picus <matti.picus@gmail.com> | 2021-12-18 19:05:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-18 11:05:35 -0600 |
| commit | bb95cf015165bcf85f99ba0d28a7a6e727ca955b (patch) | |
| tree | 17e398814b9e2ac45788f9afb4fb37fdefa76b5f /numpy | |
| parent | 0302205105161c6bbae5d45fe4e7a5a624f0dbf4 (diff) | |
| download | numpy-bb95cf015165bcf85f99ba0d28a7a6e727ca955b.tar.gz | |
DEP: remove NPY_ARRAY_UPDATEIFCOPY, deprecated in 1.14 (#20589)
* DEP: remove NPY_ARRAY_UPDATEIFCOPY, deprecated in 1.14
* remove more UPDATEIFCOPY
* typo: add missing comma
* remove a few more UPDATEIFCOPY
* Add release note
* remove UPDATEIFCOPY from comment (from review)
Diffstat (limited to 'numpy')
27 files changed, 32 insertions, 263 deletions
diff --git a/numpy/__init__.cython-30.pxd b/numpy/__init__.cython-30.pxd index 42a46d0b8..5fd6086e0 100644 --- a/numpy/__init__.cython-30.pxd +++ b/numpy/__init__.cython-30.pxd @@ -133,7 +133,6 @@ cdef extern from "numpy/arrayobject.h": NPY_ALIGNED NPY_NOTSWAPPED NPY_WRITEABLE - NPY_UPDATEIFCOPY NPY_ARR_HAS_DESCR NPY_BEHAVED @@ -165,7 +164,7 @@ cdef extern from "numpy/arrayobject.h": NPY_ARRAY_ALIGNED NPY_ARRAY_NOTSWAPPED NPY_ARRAY_WRITEABLE - NPY_ARRAY_UPDATEIFCOPY + NPY_ARRAY_WRITEBACKIFCOPY NPY_ARRAY_BEHAVED NPY_ARRAY_BEHAVED_NS diff --git a/numpy/__init__.pxd b/numpy/__init__.pxd index 97f3da2e5..03db9a0c1 100644 --- a/numpy/__init__.pxd +++ b/numpy/__init__.pxd @@ -130,7 +130,6 @@ cdef extern from "numpy/arrayobject.h": NPY_ALIGNED NPY_NOTSWAPPED NPY_WRITEABLE - NPY_UPDATEIFCOPY NPY_ARR_HAS_DESCR NPY_BEHAVED @@ -162,7 +161,7 @@ cdef extern from "numpy/arrayobject.h": NPY_ARRAY_ALIGNED NPY_ARRAY_NOTSWAPPED NPY_ARRAY_WRITEABLE - NPY_ARRAY_UPDATEIFCOPY + NPY_ARRAY_WRITEBACKIFCOPY NPY_ARRAY_BEHAVED NPY_ARRAY_BEHAVED_NS diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index 7d009ad9f..759801ccc 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -2477,11 +2477,6 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('flags', This array is a copy of some other array. The C-API function PyArray_ResolveWritebackIfCopy must be called before deallocating to the base array will be updated with the contents of this array. - UPDATEIFCOPY (U) - (Deprecated, use WRITEBACKIFCOPY) This array is a copy of some other array. - When this array is - deallocated, the base array will be updated with the contents of - this array. FNC F_CONTIGUOUS and not C_CONTIGUOUS. FORC @@ -2499,13 +2494,12 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('flags', or by using lowercased attribute names (as in ``a.flags.writeable``). Short flag names are only supported in dictionary access. - Only the WRITEBACKIFCOPY, UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be + Only the WRITEBACKIFCOPY, WRITEABLE, and ALIGNED flags can be changed by the user, via direct assignment to the attribute or dictionary entry, or by calling `ndarray.setflags`. The array flags cannot be set arbitrarily: - - UPDATEIFCOPY can only be set ``False``. - WRITEBACKIFCOPY can only be set ``False``. - ALIGNED can only be set ``True`` if the data is truly aligned. - WRITEABLE can only be set ``True`` if the array owns its own memory @@ -3907,13 +3901,13 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('setflags', """ a.setflags(write=None, align=None, uic=None) - Set array flags WRITEABLE, ALIGNED, (WRITEBACKIFCOPY and UPDATEIFCOPY), + Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively. These Boolean-valued flags affect how numpy interprets the memory area used by `a` (see Notes below). The ALIGNED flag can only be set to True if the data is actually aligned according to the type. - The WRITEBACKIFCOPY and (deprecated) UPDATEIFCOPY flags can never be set + The WRITEBACKIFCOPY and flag can never be set to True. The flag WRITEABLE can only be set to True if the array owns its own memory, or the ultimate owner of the memory exposes a writeable buffer interface, or is a string. (The exception for string is made so that @@ -3933,15 +3927,13 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('setflags', Array flags provide information about how the memory area used for the array is to be interpreted. There are 7 Boolean flags in use, only four of which can be changed by the user: - WRITEBACKIFCOPY, UPDATEIFCOPY, WRITEABLE, and ALIGNED. + WRITEBACKIFCOPY, WRITEABLE, and ALIGNED. WRITEABLE (W) the data area can be written to; ALIGNED (A) the data and strides are aligned appropriately for the hardware (as determined by the compiler); - UPDATEIFCOPY (U) (deprecated), replaced by WRITEBACKIFCOPY; - WRITEBACKIFCOPY (X) this array is a copy of some other array (referenced by .base). When the C-API function PyArray_ResolveWritebackIfCopy is called, the base array will be updated with the contents of this array. @@ -3965,7 +3957,6 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('setflags', WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False - UPDATEIFCOPY : False >>> y.setflags(write=0, align=0) >>> y.flags C_CONTIGUOUS : True @@ -3974,7 +3965,6 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('setflags', WRITEABLE : False ALIGNED : False WRITEBACKIFCOPY : False - UPDATEIFCOPY : False >>> y.setflags(uic=1) Traceback (most recent call last): File "<stdin>", line 1, in <module> diff --git a/numpy/core/_asarray.py b/numpy/core/_asarray.py index ecb4e7c39..89d422e99 100644 --- a/numpy/core/_asarray.py +++ b/numpy/core/_asarray.py @@ -78,7 +78,6 @@ def require(a, dtype=None, requirements=None, *, like=None): WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False - UPDATEIFCOPY : False >>> y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F']) >>> y.flags @@ -88,7 +87,6 @@ def require(a, dtype=None, requirements=None, *, like=None): WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False - UPDATEIFCOPY : False """ if like is not None: diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h index 2eb951486..aaaefd7de 100644 --- a/numpy/core/include/numpy/ndarrayobject.h +++ b/numpy/core/include/numpy/ndarrayobject.h @@ -152,19 +152,16 @@ extern "C" { (k)*PyArray_STRIDES(obj)[2] + \ (l)*PyArray_STRIDES(obj)[3])) -/* Move to arrayobject.c once PyArray_XDECREF_ERR is removed */ static NPY_INLINE void PyArray_DiscardWritebackIfCopy(PyArrayObject *arr) { PyArrayObject_fields *fa = (PyArrayObject_fields *)arr; if (fa && fa->base) { - if ((fa->flags & NPY_ARRAY_UPDATEIFCOPY) || - (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY)) { + if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) { PyArray_ENABLEFLAGS((PyArrayObject*)fa->base, NPY_ARRAY_WRITEABLE); Py_DECREF(fa->base); fa->base = NULL; PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEBACKIFCOPY); - PyArray_CLEARFLAGS(arr, NPY_ARRAY_UPDATEIFCOPY); } } } @@ -246,20 +243,6 @@ NPY_TITLE_KEY_check(PyObject *key, PyObject *value) #define DEPRECATE(msg) PyErr_WarnEx(PyExc_DeprecationWarning,msg,1) #define DEPRECATE_FUTUREWARNING(msg) PyErr_WarnEx(PyExc_FutureWarning,msg,1) -#if !defined(NPY_NO_DEPRECATED_API) || \ - (NPY_NO_DEPRECATED_API < NPY_1_14_API_VERSION) -static NPY_INLINE void -PyArray_XDECREF_ERR(PyArrayObject *arr) -{ - /* 2017-Nov-10 1.14 */ - DEPRECATE("PyArray_XDECREF_ERR is deprecated, call " - "PyArray_DiscardWritebackIfCopy then Py_XDECREF instead"); - PyArray_DiscardWritebackIfCopy(arr); - Py_XDECREF(arr); -} -#endif - - #ifdef __cplusplus } #endif diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h index 6240adc0c..0bd259983 100644 --- a/numpy/core/include/numpy/ndarraytypes.h +++ b/numpy/core/include/numpy/ndarraytypes.h @@ -934,7 +934,6 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); * This flag may be requested in constructor functions. * This flag may be tested for in PyArray_FLAGS(arr). */ -#define NPY_ARRAY_UPDATEIFCOPY 0x1000 /* Deprecated in 1.14 */ #define NPY_ARRAY_WRITEBACKIFCOPY 0x2000 /* @@ -965,14 +964,12 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); #define NPY_ARRAY_DEFAULT (NPY_ARRAY_CARRAY) #define NPY_ARRAY_IN_ARRAY (NPY_ARRAY_CARRAY_RO) #define NPY_ARRAY_OUT_ARRAY (NPY_ARRAY_CARRAY) -#define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY | \ - NPY_ARRAY_UPDATEIFCOPY) +#define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY) #define NPY_ARRAY_INOUT_ARRAY2 (NPY_ARRAY_CARRAY | \ NPY_ARRAY_WRITEBACKIFCOPY) #define NPY_ARRAY_IN_FARRAY (NPY_ARRAY_FARRAY_RO) #define NPY_ARRAY_OUT_FARRAY (NPY_ARRAY_FARRAY) -#define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY | \ - NPY_ARRAY_UPDATEIFCOPY) +#define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY) #define NPY_ARRAY_INOUT_FARRAY2 (NPY_ARRAY_FARRAY | \ NPY_ARRAY_WRITEBACKIFCOPY) diff --git a/numpy/core/include/numpy/noprefix.h b/numpy/core/include/numpy/noprefix.h index 2c0ce1420..cea5b0d46 100644 --- a/numpy/core/include/numpy/noprefix.h +++ b/numpy/core/include/numpy/noprefix.h @@ -165,7 +165,6 @@ #define ALIGNED NPY_ALIGNED #define NOTSWAPPED NPY_NOTSWAPPED #define WRITEABLE NPY_WRITEABLE -#define UPDATEIFCOPY NPY_UPDATEIFCOPY #define WRITEBACKIFCOPY NPY_ARRAY_WRITEBACKIFCOPY #define ARR_HAS_DESCR NPY_ARR_HAS_DESCR #define BEHAVED NPY_BEHAVED diff --git a/numpy/core/include/numpy/npy_1_7_deprecated_api.h b/numpy/core/include/numpy/npy_1_7_deprecated_api.h index 4fd4015a9..6455d40d2 100644 --- a/numpy/core/include/numpy/npy_1_7_deprecated_api.h +++ b/numpy/core/include/numpy/npy_1_7_deprecated_api.h @@ -48,7 +48,6 @@ #define NPY_ALIGNED NPY_ARRAY_ALIGNED #define NPY_NOTSWAPPED NPY_ARRAY_NOTSWAPPED #define NPY_WRITEABLE NPY_ARRAY_WRITEABLE -#define NPY_UPDATEIFCOPY NPY_ARRAY_UPDATEIFCOPY #define NPY_BEHAVED NPY_ARRAY_BEHAVED #define NPY_BEHAVED_NS NPY_ARRAY_BEHAVED_NS #define NPY_CARRAY NPY_ARRAY_CARRAY diff --git a/numpy/core/src/multiarray/_multiarray_tests.c.src b/numpy/core/src/multiarray/_multiarray_tests.c.src index 9486b7cff..4c8f241f7 100644 --- a/numpy/core/src/multiarray/_multiarray_tests.c.src +++ b/numpy/core/src/multiarray/_multiarray_tests.c.src @@ -797,25 +797,6 @@ npy_char_deprecation(PyObject* NPY_UNUSED(self), PyObject* NPY_UNUSED(args)) return (PyObject *)descr; } -/* used to test UPDATEIFCOPY usage emits deprecation warning */ -static PyObject* -npy_updateifcopy_deprecation(PyObject* NPY_UNUSED(self), PyObject* args) -{ - int flags; - PyObject* array; - if (!PyArray_Check(args)) { - PyErr_SetString(PyExc_TypeError, "test needs ndarray input"); - return NULL; - } - flags = NPY_ARRAY_CARRAY | NPY_ARRAY_UPDATEIFCOPY; - array = PyArray_FromArray((PyArrayObject*)args, NULL, flags); - if (array == NULL) - return NULL; - PyArray_ResolveWritebackIfCopy((PyArrayObject*)array); - Py_DECREF(array); - Py_RETURN_NONE; -} - /* used to test PyArray_As1D usage emits not implemented error */ static PyObject* npy_pyarrayas1d_deprecation(PyObject* NPY_UNUSED(self), PyObject* NPY_UNUSED(args)) @@ -2414,9 +2395,6 @@ static PyMethodDef Multiarray_TestsMethods[] = { {"npy_char_deprecation", npy_char_deprecation, METH_NOARGS, NULL}, - {"npy_updateifcopy_deprecation", - npy_updateifcopy_deprecation, - METH_O, NULL}, {"npy_pyarrayas1d_deprecation", npy_pyarrayas1d_deprecation, METH_NOARGS, NULL}, diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 1b197d0f2..b0c49aafe 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -75,36 +75,19 @@ PyArray_Size(PyObject *op) } } -/*NUMPY_API - * - * Precondition: 'arr' is a copy of 'base' (though possibly with different - * strides, ordering, etc.). This function sets the UPDATEIFCOPY flag and the - * ->base pointer on 'arr', so that when 'arr' is destructed, it will copy any - * changes back to 'base'. DEPRECATED, use PyArray_SetWritebackIfCopyBase - * - * Steals a reference to 'base'. - * - * Returns 0 on success, -1 on failure. - */ +/*NUMPY_API */ NPY_NO_EXPORT int PyArray_SetUpdateIfCopyBase(PyArrayObject *arr, PyArrayObject *base) { - int ret; - /* 2017-Nov -10 1.14 (for PyPy only) */ - /* 2018-April-21 1.15 (all Python implementations) */ - if (DEPRECATE("PyArray_SetUpdateIfCopyBase is deprecated, use " - "PyArray_SetWritebackIfCopyBase instead, and be sure to call " - "PyArray_ResolveWritebackIfCopy before the array is deallocated, " - "i.e. before the last call to Py_DECREF. If cleaning up from an " - "error, PyArray_DiscardWritebackIfCopy may be called instead to " - "throw away the scratch buffer.") < 0) - return -1; - ret = PyArray_SetWritebackIfCopyBase(arr, base); - if (ret >=0) { - PyArray_ENABLEFLAGS(arr, NPY_ARRAY_UPDATEIFCOPY); - PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEBACKIFCOPY); - } - return ret; + /* 2021-Dec-15 1.23*/ + PyErr_SetString(PyExc_RuntimeError, + "PyArray_SetUpdateIfCopyBase is disabled, use " + "PyArray_SetWritebackIfCopyBase instead, and be sure to call " + "PyArray_ResolveWritebackIfCopy before the array is deallocated, " + "i.e. before the last call to Py_DECREF. If cleaning up from an " + "error, PyArray_DiscardWritebackIfCopy may be called instead to " + "throw away the scratch buffer."); + return -1; } /*NUMPY_API @@ -377,9 +360,9 @@ PyArray_ResolveWritebackIfCopy(PyArrayObject * self) { PyArrayObject_fields *fa = (PyArrayObject_fields *)self; if (fa && fa->base) { - if ((fa->flags & NPY_ARRAY_UPDATEIFCOPY) || (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY)) { + if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) { /* - * UPDATEIFCOPY or WRITEBACKIFCOPY means that fa->base's data + * WRITEBACKIFCOPY means that fa->base's data * should be updated with the contents * of self. * fa->base->flags is not WRITEABLE to protect the relationship @@ -388,7 +371,6 @@ PyArray_ResolveWritebackIfCopy(PyArrayObject * self) int retval = 0; PyArray_ENABLEFLAGS(((PyArrayObject *)fa->base), NPY_ARRAY_WRITEABLE); - PyArray_CLEARFLAGS(self, NPY_ARRAY_UPDATEIFCOPY); PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY); retval = PyArray_CopyAnyInto((PyArrayObject *)fa->base, self); Py_DECREF(fa->base); @@ -462,25 +444,6 @@ array_dealloc(PyArrayObject *self) PyErr_Clear(); } } - if (PyArray_FLAGS(self) & NPY_ARRAY_UPDATEIFCOPY) { - /* DEPRECATED, remove once the flag is removed */ - char const * msg = "UPDATEIFCOPY detected in array_dealloc. " - " Required call to PyArray_ResolveWritebackIfCopy or " - "PyArray_DiscardWritebackIfCopy is missing"; - /* - * prevent reaching 0 twice and thus recursing into dealloc. - * Increasing sys.gettotalrefcount, but path should not be taken. - */ - Py_INCREF(self); - /* 2017-Nov-10 1.14 */ - WARN_IN_DEALLOC(PyExc_DeprecationWarning, msg); - retval = PyArray_ResolveWritebackIfCopy(self); - if (retval < 0) - { - PyErr_Print(); - PyErr_Clear(); - } - } /* * If fa->base is non-NULL, it is something * to DECREF -- either a view or a buffer object @@ -571,8 +534,6 @@ PyArray_DebugPrint(PyArrayObject *obj) printf(" NPY_ALIGNED"); if (fobj->flags & NPY_ARRAY_WRITEABLE) printf(" NPY_WRITEABLE"); - if (fobj->flags & NPY_ARRAY_UPDATEIFCOPY) - printf(" NPY_UPDATEIFCOPY"); if (fobj->flags & NPY_ARRAY_WRITEBACKIFCOPY) printf(" NPY_WRITEBACKIFCOPY"); printf("\n"); diff --git a/numpy/core/src/multiarray/calculation.c b/numpy/core/src/multiarray/calculation.c index 327f685d4..a985a2308 100644 --- a/numpy/core/src/multiarray/calculation.c +++ b/numpy/core/src/multiarray/calculation.c @@ -175,7 +175,7 @@ _PyArray_ArgMinMaxCommon(PyArrayObject *op, NPY_END_THREADS_DESCR(PyArray_DESCR(ap)); Py_DECREF(ap); - /* Trigger the UPDATEIFCOPY/WRITEBACKIFCOPY if necessary */ + /* Trigger the WRITEBACKIFCOPY if necessary */ if (out != NULL && out != rp) { PyArray_ResolveWritebackIfCopy(rp); Py_DECREF(rp); diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index c17402947..687e0974b 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -740,7 +740,6 @@ PyArray_NewFromDescr_int( } else { fa->flags = (flags & ~NPY_ARRAY_WRITEBACKIFCOPY); - fa->flags &= ~NPY_ARRAY_UPDATEIFCOPY; } fa->descr = descr; fa->base = (PyObject *)NULL; @@ -1753,8 +1752,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, } /* There was no array (or array-like) passed in directly. */ - if ((flags & NPY_ARRAY_WRITEBACKIFCOPY) || - (flags & NPY_ARRAY_UPDATEIFCOPY)) { + if (flags & NPY_ARRAY_WRITEBACKIFCOPY) { PyErr_SetString(PyExc_TypeError, "WRITEBACKIFCOPY used for non-array input."); Py_DECREF(dtype); @@ -1823,7 +1821,6 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, * NPY_ARRAY_WRITEABLE, * NPY_ARRAY_NOTSWAPPED, * NPY_ARRAY_ENSURECOPY, - * NPY_ARRAY_UPDATEIFCOPY, * NPY_ARRAY_WRITEBACKIFCOPY, * NPY_ARRAY_FORCECAST, * NPY_ARRAY_ENSUREARRAY, @@ -1850,9 +1847,6 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, * Fortran arrays are always behaved (aligned, * notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). * - * NPY_ARRAY_UPDATEIFCOPY is deprecated in favor of - * NPY_ARRAY_WRITEBACKIFCOPY in 1.14 - * NPY_ARRAY_WRITEBACKIFCOPY flag sets this flag in the returned * array if a copy is made and the base argument points to the (possibly) * misbehaved array. Before returning to python, PyArray_ResolveWritebackIfCopy @@ -2004,31 +1998,8 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) return NULL; } - if (flags & NPY_ARRAY_UPDATEIFCOPY) { - /* This is the ONLY place the NPY_ARRAY_UPDATEIFCOPY flag - * is still used. - * Can be deleted once the flag itself is removed - */ - /* 2017-Nov-10 1.14 */ - if (DEPRECATE( - "NPY_ARRAY_UPDATEIFCOPY, NPY_ARRAY_INOUT_ARRAY, and " - "NPY_ARRAY_INOUT_FARRAY are deprecated, use NPY_WRITEBACKIFCOPY, " - "NPY_ARRAY_INOUT_ARRAY2, or NPY_ARRAY_INOUT_FARRAY2 respectively " - "instead, and call PyArray_ResolveWritebackIfCopy before the " - "array is deallocated, i.e. before the last call to Py_DECREF.") < 0) { - Py_DECREF(ret); - return NULL; - } - Py_INCREF(arr); - if (PyArray_SetWritebackIfCopyBase(ret, arr) < 0) { - Py_DECREF(ret); - return NULL; - } - PyArray_ENABLEFLAGS(ret, NPY_ARRAY_UPDATEIFCOPY); - PyArray_CLEARFLAGS(ret, NPY_ARRAY_WRITEBACKIFCOPY); - } - else if (flags & NPY_ARRAY_WRITEBACKIFCOPY) { + if (flags & NPY_ARRAY_WRITEBACKIFCOPY) { Py_INCREF(arr); if (PyArray_SetWritebackIfCopyBase(ret, arr) < 0) { Py_DECREF(ret); diff --git a/numpy/core/src/multiarray/flagsobject.c b/numpy/core/src/multiarray/flagsobject.c index 3b1b4f406..b5bd7c8c1 100644 --- a/numpy/core/src/multiarray/flagsobject.c +++ b/numpy/core/src/multiarray/flagsobject.c @@ -238,25 +238,6 @@ _define_get_warn(NPY_ARRAY_ALIGNED| NPY_ARRAY_C_CONTIGUOUS, carray) static PyObject * -arrayflags_updateifcopy_get(PyArrayFlagsObject *self, void *NPY_UNUSED(ignored)) -{ - PyObject *item; - /* 2017-Nov-10 1.14 */ - if(DEPRECATE("UPDATEIFCOPY deprecated, use WRITEBACKIFCOPY instead") < 0) { - return NULL; - } - if ((self->flags & (NPY_ARRAY_UPDATEIFCOPY)) == (NPY_ARRAY_UPDATEIFCOPY)) { - item = Py_True; - } - else { - item = Py_False; - } - Py_INCREF(item); - return item; -} - - -static PyObject * arrayflags_forc_get(PyArrayFlagsObject *self, void *NPY_UNUSED(ignored)) { PyObject *item; @@ -314,36 +295,6 @@ arrayflags_num_get(PyArrayFlagsObject *self, void *NPY_UNUSED(ignored)) /* relies on setflags order being write, align, uic */ static int -arrayflags_updateifcopy_set( - PyArrayFlagsObject *self, PyObject *obj, void *NPY_UNUSED(ignored)) -{ - PyObject *res; - - if (obj == NULL) { - PyErr_SetString(PyExc_AttributeError, - "Cannot delete flags updateifcopy attribute"); - return -1; - } - if (self->arr == NULL) { - PyErr_SetString(PyExc_ValueError, - "Cannot set flags on array scalars."); - return -1; - } - /* 2017-Nov-10 1.14 */ - if(DEPRECATE("UPDATEIFCOPY deprecated, use WRITEBACKIFCOPY instead") < 0) { - return -1; - } - res = PyObject_CallMethod(self->arr, "setflags", "OOO", Py_None, Py_None, - (PyObject_IsTrue(obj) ? Py_True : Py_False)); - if (res == NULL) { - return -1; - } - Py_DECREF(res); - return 0; -} - -/* relies on setflags order being write, align, uic */ -static int arrayflags_writebackifcopy_set( PyArrayFlagsObject *self, PyObject *obj, void *NPY_UNUSED(ignored)) { @@ -473,10 +424,6 @@ static PyGetSetDef arrayflags_getsets[] = { (getter)arrayflags_fortran_get, NULL, NULL, NULL}, - {"updateifcopy", - (getter)arrayflags_updateifcopy_get, - (setter)arrayflags_updateifcopy_set, - NULL, NULL}, {"writebackifcopy", (getter)arrayflags_writebackifcopy_get, (setter)arrayflags_writebackifcopy_set, @@ -574,8 +521,6 @@ arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind) return arrayflags_aligned_get(self, NULL); case 'X': return arrayflags_writebackifcopy_get(self, NULL); - case 'U': - return arrayflags_updateifcopy_get(self, NULL); default: goto fail; } @@ -631,9 +576,6 @@ arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind) } break; case 12: - if (strncmp(key, "UPDATEIFCOPY", n) == 0) { - return arrayflags_updateifcopy_get(self, NULL); - } if (strncmp(key, "C_CONTIGUOUS", n) == 0) { return arrayflags_contiguous_get(self, NULL); } @@ -684,10 +626,6 @@ arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item) ((n==1) && (strncmp(key, "A", n) == 0))) { return arrayflags_aligned_set(self, item, NULL); } - else if (((n==12) && (strncmp(key, "UPDATEIFCOPY", n) == 0)) || - ((n==1) && (strncmp(key, "U", n) == 0))) { - return arrayflags_updateifcopy_set(self, item, NULL); - } else if (((n==15) && (strncmp(key, "WRITEBACKIFCOPY", n) == 0)) || ((n==1) && (strncmp(key, "X", n) == 0))) { return arrayflags_writebackifcopy_set(self, item, NULL); @@ -721,16 +659,14 @@ arrayflags_print(PyArrayFlagsObject *self) return PyUnicode_FromFormat( " %s : %s\n %s : %s\n" " %s : %s\n %s : %s%s\n" - " %s : %s\n %s : %s\n" - " %s : %s\n", + " %s : %s\n %s : %s\n", "C_CONTIGUOUS", _torf_(fl, NPY_ARRAY_C_CONTIGUOUS), "F_CONTIGUOUS", _torf_(fl, NPY_ARRAY_F_CONTIGUOUS), "OWNDATA", _torf_(fl, NPY_ARRAY_OWNDATA), "WRITEABLE", _torf_(fl, NPY_ARRAY_WRITEABLE), _warn_on_write, "ALIGNED", _torf_(fl, NPY_ARRAY_ALIGNED), - "WRITEBACKIFCOPY", _torf_(fl, NPY_ARRAY_WRITEBACKIFCOPY), - "UPDATEIFCOPY", _torf_(fl, NPY_ARRAY_UPDATEIFCOPY) + "WRITEBACKIFCOPY", _torf_(fl, NPY_ARRAY_WRITEBACKIFCOPY) ); } diff --git a/numpy/core/src/multiarray/getset.c b/numpy/core/src/multiarray/getset.c index 2544ca9e7..b9bd27393 100644 --- a/numpy/core/src/multiarray/getset.c +++ b/numpy/core/src/multiarray/getset.c @@ -404,12 +404,10 @@ array_data_set(PyArrayObject *self, PyObject *op, void *NPY_UNUSED(ignored)) Py_CLEAR(((PyArrayObject_fields *)self)->mem_handler); } if (PyArray_BASE(self)) { - if ((PyArray_FLAGS(self) & NPY_ARRAY_WRITEBACKIFCOPY) || - (PyArray_FLAGS(self) & NPY_ARRAY_UPDATEIFCOPY)) { + if (PyArray_FLAGS(self) & NPY_ARRAY_WRITEBACKIFCOPY) { PyArray_ENABLEFLAGS((PyArrayObject *)PyArray_BASE(self), NPY_ARRAY_WRITEABLE); PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY); - PyArray_CLEARFLAGS(self, NPY_ARRAY_UPDATEIFCOPY); } Py_DECREF(PyArray_BASE(self)); ((PyArrayObject_fields *)self)->base = NULL; @@ -634,7 +632,7 @@ array_struct_get(PyArrayObject *self, void *NPY_UNUSED(ignored)) inter->flags = inter->flags & ~NPY_ARRAY_WRITEABLE; } /* reset unused flags */ - inter->flags &= ~(NPY_ARRAY_WRITEBACKIFCOPY | NPY_ARRAY_UPDATEIFCOPY |NPY_ARRAY_OWNDATA); + inter->flags &= ~(NPY_ARRAY_WRITEBACKIFCOPY | NPY_ARRAY_OWNDATA); if (PyArray_ISNOTSWAPPED(self)) inter->flags |= NPY_ARRAY_NOTSWAPPED; /* * Copy shape and strides over since these can be reset diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 014a863d5..5d515d013 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -3254,7 +3254,7 @@ PyArray_MapIterNew(npy_index_info *indices , int index_num, int index_type, * If copy_if_overlap != 0, check if `a` has memory overlap with any of the * arrays in `index` and with `extra_op`. If yes, make copies as appropriate * to avoid problems if `a` is modified during the iteration. - * `iter->array` may contain a copied array (UPDATEIFCOPY/WRITEBACKIFCOPY set). + * `iter->array` may contain a copied array (WRITEBACKIFCOPY set). */ NPY_NO_EXPORT PyObject * PyArray_MapIterArrayCopyIfOverlap(PyArrayObject * a, PyObject * index, diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index b0b6f42f1..1adf79baf 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -2065,7 +2065,6 @@ array_setstate(PyArrayObject *self, PyObject *args) fa->base = NULL; PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY); - PyArray_CLEARFLAGS(self, NPY_ARRAY_UPDATEIFCOPY); if (PyArray_DIMS(self) != NULL) { npy_free_cache_dim_array(self); @@ -2621,7 +2620,6 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds) } else { PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY); - PyArray_CLEARFLAGS(self, NPY_ARRAY_UPDATEIFCOPY); Py_XDECREF(fa->base); fa->base = NULL; } diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 576c39f5d..d1627d639 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4639,7 +4639,6 @@ set_flaginfo(PyObject *d) _addnew(FORTRAN, NPY_ARRAY_F_CONTIGUOUS, F); _addnew(CONTIGUOUS, NPY_ARRAY_C_CONTIGUOUS, C); _addnew(ALIGNED, NPY_ARRAY_ALIGNED, A); - _addnew(UPDATEIFCOPY, NPY_ARRAY_UPDATEIFCOPY, U); _addnew(WRITEBACKIFCOPY, NPY_ARRAY_WRITEBACKIFCOPY, X); _addnew(WRITEABLE, NPY_ARRAY_WRITEABLE, W); _addone(C_CONTIGUOUS, NPY_ARRAY_C_CONTIGUOUS); diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index 013526ff0..907761874 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -1203,8 +1203,7 @@ gentype_struct_get(PyObject *self, void *NPY_UNUSED(ignored)) inter->two = 2; inter->nd = 0; inter->flags = PyArray_FLAGS(arr); - inter->flags &= ~(NPY_ARRAY_UPDATEIFCOPY | NPY_ARRAY_WRITEBACKIFCOPY | - NPY_ARRAY_OWNDATA); + inter->flags &= ~(NPY_ARRAY_WRITEBACKIFCOPY | NPY_ARRAY_OWNDATA); inter->flags |= NPY_ARRAY_NOTSWAPPED; inter->typekind = PyArray_DESCR(arr)->kind; inter->itemsize = PyArray_DESCR(arr)->elsize; diff --git a/numpy/core/src/multiarray/temp_elide.c b/numpy/core/src/multiarray/temp_elide.c index f615aa336..34248076c 100644 --- a/numpy/core/src/multiarray/temp_elide.c +++ b/numpy/core/src/multiarray/temp_elide.c @@ -286,7 +286,6 @@ can_elide_temp(PyObject *olhs, PyObject *orhs, int *cannot) !PyArray_ISNUMBER(alhs) || !PyArray_CHKFLAGS(alhs, NPY_ARRAY_OWNDATA) || !PyArray_ISWRITEABLE(alhs) || - PyArray_CHKFLAGS(alhs, NPY_ARRAY_UPDATEIFCOPY) || PyArray_CHKFLAGS(alhs, NPY_ARRAY_WRITEBACKIFCOPY) || PyArray_NBYTES(alhs) < NPY_MIN_ELIDE_BYTES) { return 0; @@ -365,7 +364,6 @@ can_elide_temp_unary(PyArrayObject * m1) !PyArray_ISNUMBER(m1) || !PyArray_CHKFLAGS(m1, NPY_ARRAY_OWNDATA) || !PyArray_ISWRITEABLE(m1) || - PyArray_CHKFLAGS(m1, NPY_ARRAY_UPDATEIFCOPY) || PyArray_NBYTES(m1) < NPY_MIN_ELIDE_BYTES) { return 0; } diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index a269eb519..d148c89f5 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -380,18 +380,6 @@ class TestPyArray_AS2D(_DeprecationTestCase): assert_raises(NotImplementedError, npy_pyarrayas2d_deprecation) -class Test_UPDATEIFCOPY(_DeprecationTestCase): - """ - v1.14 deprecates creating an array with the UPDATEIFCOPY flag, use - WRITEBACKIFCOPY instead - """ - def test_npy_updateifcopy_deprecation(self): - from numpy.core._multiarray_tests import npy_updateifcopy_deprecation - arr = np.arange(9).reshape(3, 3) - v = arr.T - self.assert_deprecated(npy_updateifcopy_deprecation, args=(v,)) - - class TestDatetimeEvent(_DeprecationTestCase): # 2017-08-11, 1.14.0 def test_3_tuple(self): diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 2fd94f245..0c611abb5 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -234,11 +234,6 @@ class TestFlags: assert_equal(self.a.flags.owndata, True) assert_equal(self.a.flags.writeable, True) assert_equal(self.a.flags.aligned, True) - with assert_warns(DeprecationWarning): - assert_equal(self.a.flags.updateifcopy, False) - with assert_warns(DeprecationWarning): - assert_equal(self.a.flags['U'], False) - assert_equal(self.a.flags['UPDATEIFCOPY'], False) assert_equal(self.a.flags.writebackifcopy, False) assert_equal(self.a.flags['X'], False) assert_equal(self.a.flags['WRITEBACKIFCOPY'], False) @@ -5381,19 +5376,8 @@ class TestFlat: assert_(c.flags.writeable is False) assert_(d.flags.writeable is False) - # for 1.14 all are set to non-writeable on the way to replacing the - # UPDATEIFCOPY array returned for non-contiguous arrays. assert_(e.flags.writeable is True) assert_(f.flags.writeable is False) - with assert_warns(DeprecationWarning): - assert_(c.flags.updateifcopy is False) - with assert_warns(DeprecationWarning): - assert_(d.flags.updateifcopy is False) - with assert_warns(DeprecationWarning): - assert_(e.flags.updateifcopy is False) - with assert_warns(DeprecationWarning): - # UPDATEIFCOPY is removed. - assert_(f.flags.updateifcopy is False) assert_(c.flags.writebackifcopy is False) assert_(d.flags.writebackifcopy is False) assert_(e.flags.writebackifcopy is False) diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index ed775cac6..d96c14e54 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -828,7 +828,7 @@ def test_iter_nbo_align_contig(): casting='equiv', op_dtypes=[np.dtype('f4')]) with i: - # context manager triggers UPDATEIFCOPY on i at exit + # context manager triggers WRITEBACKIFCOPY on i at exit assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder) assert_equal(i.operands[0].dtype.byteorder, a.dtype.byteorder) assert_equal(i.operands[0], a) diff --git a/numpy/ctypeslib.py b/numpy/ctypeslib.py index 8d105a248..c4bafca1b 100644 --- a/numpy/ctypeslib.py +++ b/numpy/ctypeslib.py @@ -170,7 +170,7 @@ def _num_fromflags(flaglist): return num _flagnames = ['C_CONTIGUOUS', 'F_CONTIGUOUS', 'ALIGNED', 'WRITEABLE', - 'OWNDATA', 'UPDATEIFCOPY', 'WRITEBACKIFCOPY'] + 'OWNDATA', 'WRITEBACKIFCOPY'] def _flags_fromnum(num): res = [] for key in _flagnames: @@ -261,7 +261,6 @@ def ndpointer(dtype=None, ndim=None, shape=None, flags=None): - WRITEABLE / W - ALIGNED / A - WRITEBACKIFCOPY / X - - UPDATEIFCOPY / U Returns ------- diff --git a/numpy/ctypeslib.pyi b/numpy/ctypeslib.pyi index 1c396d240..d2a87fd03 100644 --- a/numpy/ctypeslib.pyi +++ b/numpy/ctypeslib.pyi @@ -93,7 +93,6 @@ _FlagsKind = L[ 'ALIGNED', 'A', 'WRITEABLE', 'W', 'OWNDATA', 'O', - 'UPDATEIFCOPY', 'U', 'WRITEBACKIFCOPY', 'X', ] diff --git a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c index ea47e0555..c8ae7b9dc 100644 --- a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +++ b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c @@ -202,7 +202,6 @@ PyMODINIT_FUNC PyInit_test_array_from_pyobj_ext(void) { ADDCONST("ENSUREARRAY", NPY_ARRAY_ENSUREARRAY); ADDCONST("ALIGNED", NPY_ARRAY_ALIGNED); ADDCONST("WRITEABLE", NPY_ARRAY_WRITEABLE); - ADDCONST("UPDATEIFCOPY", NPY_ARRAY_UPDATEIFCOPY); ADDCONST("WRITEBACKIFCOPY", NPY_ARRAY_WRITEBACKIFCOPY); ADDCONST("BEHAVED", NPY_ARRAY_BEHAVED); diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py index f7c32f068..5a084bc3e 100644 --- a/numpy/f2py/tests/test_array_from_pyobj.py +++ b/numpy/f2py/tests/test_array_from_pyobj.py @@ -56,7 +56,6 @@ def flags2names(flags): "NOTSWAPPED", "WRITEABLE", "WRITEBACKIFCOPY", - "UPDATEIFCOPY", "BEHAVED", "BEHAVED_RO", "CARRAY", diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 12836967c..e0e5403a9 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -4811,7 +4811,6 @@ class MaskedArray(ndarray): WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False - UPDATEIFCOPY : False """ return self.flags['CONTIGUOUS'] |
