[Numpy-svn] r3252 - in trunk/numpy/core: . src

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Oct 5 02:40:44 EDT 2006


Author: oliphant
Date: 2006-10-05 01:40:42 -0500 (Thu, 05 Oct 2006)
New Revision: 3252

Modified:
   trunk/numpy/core/records.py
   trunk/numpy/core/src/arrayobject.c
Log:
Fix issue #313.  Also make sure shape attribute of dtype object always returns a tuple.

Modified: trunk/numpy/core/records.py
===================================================================
--- trunk/numpy/core/records.py	2006-10-05 05:49:08 UTC (rev 3251)
+++ trunk/numpy/core/records.py	2006-10-05 06:40:42 UTC (rev 3252)
@@ -285,10 +285,6 @@
             formats += ','
         formats=formats[:-1]
 
-    for obj in arrayList:
-        if obj.shape != shape:
-            raise ValueError, "array has different shape"
-
     if dtype is not None:
         descr = sb.dtype(dtype)
         _names = descr.names
@@ -296,7 +292,22 @@
         parsed = format_parser(formats, names, titles, aligned, byteorder)
         _names = parsed._names
         descr = parsed._descr
+
+    # Determine shape from data-type.
+    if len(descr) != len(arrayList):
+        raise ValueError, "mismatch between the number of fields "\
+              "and the number of arrays"
+    
+    d0 = descr[0].shape
+    nn = len(d0)
+    if nn > 0:
+        shape = shape[nn:]
         
+    for k, obj in enumerate(arrayList):
+        nn = len(descr[k].shape)
+        if obj.shape[nn:] != shape:
+            raise ValueError, "array-shape mismatch in array", k
+        
     _array = recarray(shape, descr)
 
     # populate the record array (makes a copy)

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-05 05:49:08 UTC (rev 3251)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-05 06:40:42 UTC (rev 3252)
@@ -10634,8 +10634,11 @@
         if (self->subarray == NULL) {
                 return PyTuple_New(0);
         }
-        Py_INCREF(self->subarray->shape);
-        return (PyObject *)(self->subarray->shape);
+        if (PyTuple_Check(self->subarray->shape)) {
+                Py_INCREF(self->subarray->shape);
+                return (PyObject *)(self->subarray->shape);
+        }
+        return Py_BuildValue("(O)", self->subarray->shape);
 }
 
 static PyObject *




More information about the Numpy-svn mailing list