diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 15 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index e00df6762..d0370fe6b 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -730,6 +730,21 @@ VOID_getitem(void *input, void *vap) return (PyObject *)ret; } + /* 2017-11-26, 1.14 */ + if (DEPRECATE_FUTUREWARNING( + "the `.item()` method of unstructured void types will return an " + "immutable `bytes` object in the near future, the same as " + "returned by `bytes(void_obj)`, instead of the mutable memoryview " + "or integer array returned in numpy 1.13.") < 0) { + return NULL; + } + /* + * In the future all the code below will be replaced by + * + * For unstructured void types like V4, return a bytes object (copy). + * return PyBytes_FromStringAndSize(PyArray_DATA(ap), descr->elsize); + */ + if (PyDataType_FLAGCHK(descr, NPY_ITEM_HASOBJECT) || PyDataType_FLAGCHK(descr, NPY_ITEM_IS_POINTER)) { PyErr_SetString(PyExc_ValueError, diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 73edaec0b..a3b011454 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -2260,6 +2260,15 @@ class TestRegression(object): item2 = copy.copy(item) assert_equal(item, item2) + def test_void_item_memview(self): + va = np.zeros(10, 'V4') + # for now, there is just a futurewarning + assert_warns(FutureWarning, va[:1].item) + # in the future, test we got a bytes copy: + #x = va[:1].item() + #va[0] = b'\xff\xff\xff\xff' + #del va + #assert_equal(x, b'\x00\x00\x00\x00') if __name__ == "__main__": run_module_suite() |