diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-09-30 23:33:23 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-09-30 23:33:23 +0000 |
commit | 6c52e6fc05f89f13871b79074ea8891c11092d35 (patch) | |
tree | b0570cda88d114c16606d2471a573a737f1f83d1 /numpy/core | |
parent | 87a1a601efc59a98dfc67b2e863189b44deff4a6 (diff) | |
download | numpy-6c52e6fc05f89f13871b79074ea8891c11092d35.tar.gz |
Fix setting unicode/string arrays with 0-d arrays of type unicode and/or string.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/arraytypes.inc.src | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 2 |
2 files changed, 8 insertions, 4 deletions
diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index edc23ae1f..3dfa1b0ae 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -313,11 +313,13 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) #endif if (!PyString_Check(op) && !PyUnicode_Check(op) && - PySequence_Check(op)) { + PySequence_Check(op) && PySequence_Size(op) > 0) { PyErr_SetString(PyExc_ValueError, "setting an array element with a sequence"); return -1; } + /* Sequence_Size might have returned an error */ + if (PyErr_Occurred()) PyErr_Clear(); if ((temp=PyObject_Unicode(op)) == NULL) return -1; ptr = PyUnicode_AS_UNICODE(temp); if ((ptr == NULL) || (PyErr_Occurred())) { @@ -375,12 +377,14 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) Py_ssize_t len; PyObject *temp=NULL; - if (!PyString_Check(op) && !PyUnicode_Check(op) && - PySequence_Check(op)) { + if (!PyString_Check(op) && !PyUnicode_Check(op) && + PySequence_Check(op) && PySequence_Size(op) > 0) { PyErr_SetString(PyExc_ValueError, "setting an array element with a sequence"); return -1; } + /* Sequence_Size might have returned an error */ + if (PyErr_Occurred()) PyErr_Clear(); if ((temp = PyObject_Str(op)) == NULL) return -1; if (PyString_AsStringAndSize(temp, &ptr, &len) == -1) { diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 54759fdff..58c93947d 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -166,7 +166,7 @@ class test_zero_rank(NumpyTestCase): x[i] = v self.failUnlessRaises(IndexError, assign, a, 0, 42) self.failUnlessRaises(IndexError, assign, b, 0, '') - self.failUnlessRaises(TypeError, assign, a, (), '') + self.failUnlessRaises(ValueError, assign, a, (), '') def check_newaxis(self): a,b = self.d |