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

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Oct 18 13:15:32 CDT 2006


Author: oliphant
Date: 2006-10-18 13:15:26 -0500 (Wed, 18 Oct 2006)
New Revision: 3359

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Fix-up so that if on creation, a string or unicode data-type has an empty elsize it is reset to the size of one character.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-18 18:05:35 UTC (rev 3358)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-18 18:15:26 UTC (rev 3359)
@@ -5255,9 +5255,15 @@
         size = 1;
         sd = (size_t) descr->elsize;
         if (sd == 0) {
-                PyErr_SetString(PyExc_ValueError, "Empty data-type");
-                Py_DECREF(descr);
-                return NULL;
+                if (!PyDataType_ISSTRING(descr)) {
+                        PyErr_SetString(PyExc_ValueError, "Empty data-type");
+                        Py_DECREF(descr);
+                        return NULL;
+                }
+                PyArray_DESCR_REPLACE(descr);
+                if (descr->type_num == NPY_STRING) descr->elsize = 1;
+                else descr->elsize = sizeof(PyArray_UCS4);
+                sd = (size_t) descr->elsize;  
         }
         largest = MAX_INTP / sd;
         for (i=0;i<nd;i++) {



More information about the Numpy-svn mailing list