[Numpy-svn] r3237 - in trunk/numpy/core: src tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Sep 30 18:33:29 CDT 2006


Author: oliphant
Date: 2006-09-30 18:33:23 -0500 (Sat, 30 Sep 2006)
New Revision: 3237

Modified:
   trunk/numpy/core/src/arraytypes.inc.src
   trunk/numpy/core/tests/test_multiarray.py
Log:
Fix setting unicode/string arrays with 0-d arrays of type unicode and/or string.

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2006-09-30 21:02:52 UTC (rev 3236)
+++ trunk/numpy/core/src/arraytypes.inc.src	2006-09-30 23:33:23 UTC (rev 3237)
@@ -313,11 +313,13 @@
 #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 @@
         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) {

Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py	2006-09-30 21:02:52 UTC (rev 3236)
+++ trunk/numpy/core/tests/test_multiarray.py	2006-09-30 23:33:23 UTC (rev 3237)
@@ -166,7 +166,7 @@
             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



More information about the Numpy-svn mailing list