diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-10-18 18:15:26 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-10-18 18:15:26 +0000 |
commit | b022765aa487070866663b1707e4a2a0d8ead2e8 (patch) | |
tree | 88d49b24f895ea4e658bcd9566d1861854f6df12 /numpy/core/src/arrayobject.c | |
parent | 2e7c822ee511d36b36dc5df9b35bbacccfe366e5 (diff) | |
download | numpy-b022765aa487070866663b1707e4a2a0d8ead2e8.tar.gz |
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.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 2c77622a4..b8f3bbad2 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -5255,9 +5255,15 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, 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++) { |