diff options
author | Travis Oliphant <oliphant@enthought.com> | 2009-09-23 22:15:10 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2009-09-23 22:15:10 +0000 |
commit | ab5776e91262767af584bede2ee945793de5387a (patch) | |
tree | c604215027548337579f75a553a09da30669b87d /numpy/core | |
parent | 65d6067edccb62ac5f8a01f83ac604e5392b6f1a (diff) | |
download | numpy-ab5776e91262767af584bede2ee945793de5387a.tar.gz |
Fix bug in array descriptor conversion when third argument to record array is a tuple of array scalars.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/_internal.py | 2 | ||||
-rw-r--r-- | numpy/core/include/numpy/ndarrayobject.h | 5 | ||||
-rw-r--r-- | numpy/core/src/multiarray/descriptor.c | 18 |
3 files changed, 23 insertions, 2 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index b89c94d9b..920667623 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -3,7 +3,7 @@ import re import sys -from _mx_datetime_parser import * +#from _mx_datetime_parser import * if (sys.byteorder == 'little'): _nbo = '<' diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h index 34b080732..efdbd926b 100644 --- a/numpy/core/include/numpy/ndarrayobject.h +++ b/numpy/core/include/numpy/ndarrayobject.h @@ -1293,6 +1293,11 @@ typedef struct { #define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \ PyArray_CheckScalar(obj)) +#define PyArray_IsIntegerScalar(obj) (PyInt_Check(obj) || \ + PyLong_Check(obj) || \ + PyArray_IsScalar((obj), Integer)) + + #define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? \ Py_INCREF(m), (m) : \ (PyArrayObject *)(PyArray_Copy(m))) diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c index f1b36c33c..127a17b9b 100644 --- a/numpy/core/src/multiarray/descriptor.c +++ b/numpy/core/src/multiarray/descriptor.c @@ -754,6 +754,20 @@ _convert_from_commastring(PyObject *obj, int align) return res; } +static int +_is_tuple_of_integers(PyObject *obj) +{ + int i, n; + + if (!PyTuple_Check(obj)) return 0; + if (i=0; i<PyTuple_GET_SIZE(obj); i++) { + if (!PyArray_IsIntegerScalar(PyTuple_GET_ITEM(obj, i))) { + return 0; + } + } + return 1; +} + /* * A tuple type would be either (generic typeobject, typesize) * or (fixed-length data-type, shape) @@ -776,7 +790,9 @@ _use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) PyArray_Descr *conv; *errflag = 0; - if (!PyArray_DescrConverter(newobj, &conv)) { + if (PyArray_IsScalar(newobj, Integer) || + _is_tuple_of_integers(newobj) || + !PyArray_DescrConverter(newobj, &conv)) { return NULL; } *errflag = 1; |