[Numpy-svn] r8153 - in trunk/numpy/core: src/multiarray tests

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:10:05 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:10:04 -0600 (Sat, 20 Feb 2010)
New Revision: 8153

Modified:
   trunk/numpy/core/src/multiarray/ctors.c
   trunk/numpy/core/tests/test_multiarray.py
Log:
BUG: core: make sure PyArray_FromAny respects wanted type and flags also for PEP 3118 objects

Modified: trunk/numpy/core/src/multiarray/ctors.c
===================================================================
--- trunk/numpy/core/src/multiarray/ctors.c	2010-02-20 18:09:45 UTC (rev 8152)
+++ trunk/numpy/core/src/multiarray/ctors.c	2010-02-20 18:10:04 UTC (rev 8153)
@@ -1691,7 +1691,7 @@
         strides[0] = view->itemsize;
     }
 
-    flags = (view->readonly ? 0 : NPY_WRITEABLE);
+    flags = BEHAVED & (view->readonly ? ~NPY_WRITEABLE : ~0);
     r = PyArray_NewFromDescr(&PyArray_Type, descr,
                              nd, shape, strides, view->buf,
                              flags, NULL);
@@ -1752,7 +1752,12 @@
     else if (!PyBytes_Check(op) && !PyUnicode_Check(op) &&
              _array_from_buffer_3118(op, &r) == 0) {
         /* PEP 3118 buffer -- but don't accept Bytes objects here */
-        r = r;
+        PyObject *new;
+        if (newtype != NULL || flags != 0) {
+            new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);
+            Py_DECREF(r);
+            r = new;
+        }
     }
     else if (PyArray_HasArrayInterfaceType(op, newtype, context, r)) {
         PyObject *new;

Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py	2010-02-20 18:09:45 UTC (rev 8152)
+++ trunk/numpy/core/tests/test_multiarray.py	2010-02-20 18:10:04 UTC (rev 8153)
@@ -1461,8 +1461,13 @@
             obj = np.asarray(obj)
             x = memoryview(obj)
             y = np.asarray(x)
+            y2 = np.array(x)
+            assert not y.flags.owndata
+            assert y2.flags.owndata
             assert y.dtype == obj.dtype, (obj, y)
             assert_array_equal(obj, y)
+            assert y2.dtype == obj.dtype, (obj, y2)
+            assert_array_equal(obj, y2)
 
         def test_roundtrip(self):
             x = np.array([1,2,3,4,5], dtype='i4')



More information about the Numpy-svn mailing list