[Numpy-svn] r3331 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Oct 13 14:56:20 CDT 2006


Author: oliphant
Date: 2006-10-13 14:56:17 -0500 (Fri, 13 Oct 2006)
New Revision: 3331

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Fix ticket #344: normalize repr of dtypes with shapes.  Also change align argument in dtype constructor to be a boolean.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-13 19:37:48 UTC (rev 3330)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-13 19:56:17 UTC (rev 3331)
@@ -10792,12 +10792,13 @@
 {
         PyObject *odescr;
         PyArray_Descr *descr, *conv;
-        int align=0;
+        Bool align=FALSE;
         Bool copy=FALSE;
         static char *kwlist[] = {"dtype", "align", "copy", NULL};
 
-        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO&",
-                                         kwlist, &odescr, &align,
+        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&",
+                                         kwlist, &odescr, 
+                                         PyArray_BoolConverter, &align,
                                          PyArray_BoolConverter, &copy))
                 return NULL;
 
@@ -11160,6 +11161,7 @@
         else if (self->subarray) {
                 PyObject *p;
                 PyObject *t = PyString_FromString("(");
+                PyObject *sh;
                 p = arraydescr_str(self->subarray->base);
                 if (!self->subarray->base->names && !self->subarray->base->subarray) {
                         PyObject *t=PyString_FromString("'");
@@ -11169,7 +11171,15 @@
                 }
                 PyString_ConcatAndDel(&t, p);
                 PyString_ConcatAndDel(&t, PyString_FromString(","));
-                PyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));
+                if (!PyTuple_Check(self->subarray->shape)) {
+                        sh = Py_BuildValue("(O)", self->subarray->shape);
+                }
+                else {
+                        sh = self->subarray->shape;
+                        Py_INCREF(sh);
+                }
+                PyString_ConcatAndDel(&t, PyObject_Str(sh));
+                Py_DECREF(sh);
                 PyString_ConcatAndDel(&t, PyString_FromString(")"));
                 sub = t;
         }



More information about the Numpy-svn mailing list