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

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Sep 23 13:36:03 CDT 2006


Author: oliphant
Date: 2006-09-23 13:35:46 -0500 (Sat, 23 Sep 2006)
New Revision: 3213

Modified:
   trunk/numpy/core/numeric.py
   trunk/numpy/core/src/arrayobject.c
Log:
Fix ticket #289 plus improve the way array data-types print and arrays represent themselves.

Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py	2006-09-23 18:04:13 UTC (rev 3212)
+++ trunk/numpy/core/numeric.py	2006-09-23 18:35:46 UTC (rev 3213)
@@ -427,7 +427,7 @@
         if issubclass(arr.dtype.type, flexible):
             typename = str(arr.dtype)
             lf = '\n'+' '*len("array(")
-        return cName + "(%s, %sdtype=%s)" % (lst, lf, typename)
+        return cName + "(%s, %sdtype='%s')" % (lst, lf, typename)
 
 def array_str(a, max_line_width=None, precision=None, suppress_small=None):
     return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-09-23 18:04:13 UTC (rev 3212)
+++ trunk/numpy/core/src/arrayobject.c	2006-09-23 18:35:46 UTC (rev 3213)
@@ -7739,6 +7739,12 @@
         if (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}
         type = newtype->type_num;
         itemsize = newtype->elsize;
+        if (itemsize == 0) {
+                PyArray_DESCR_REPLACE(newtype);
+                if (newtype == NULL) return NULL;
+                newtype->elsize = oldtype->elsize;
+                itemsize = newtype->elsize;
+        }
 
         /* Don't copy if sizes are compatible */
         if ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {
@@ -11126,13 +11132,11 @@
                 PyString_ConcatAndDel(&t, PyString_FromString(")"));
                 sub = t;
         }
+        else if (PyDataType_ISFLEXIBLE(self) || !PyArray_ISNBO(self->byteorder)) {
+                sub = arraydescr_protocol_typestr_get(self);
+        }
         else {
-                if (!PyArray_ISNBO(self->byteorder)) {
-                        sub = arraydescr_protocol_typestr_get(self);
-                }
-                else {
-                        sub = arraydescr_typename_get(self);
-                }
+                sub = arraydescr_typename_get(self);
         }
         return sub;
 }



More information about the Numpy-svn mailing list