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

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Sep 4 18:42:23 EDT 2006


Author: oliphant
Date: 2006-09-04 17:42:18 -0500 (Mon, 04 Sep 2006)
New Revision: 3112

Modified:
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/tests/test_regression.py
Log:
Fix object array creation to revert to previous behavior

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-09-04 22:04:31 UTC (rev 3111)
+++ trunk/numpy/core/src/arrayobject.c	2006-09-04 22:42:18 UTC (rev 3112)
@@ -7146,7 +7146,7 @@
 /* steals reference to typecode */
 static PyObject *
 Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
-                   int min_depth, int max_depth, int isobject)
+                   int min_depth, int max_depth)
 {
         PyArrayObject *r;
         int nd;
@@ -7157,9 +7157,6 @@
         int type = typecode->type_num;
         int itemsize = typecode->elsize;
 
-        if (isobject)
-                return ObjectArray_FromNestedList(s, typecode, fortran);
-
         stop_at_string = ((type == PyArray_OBJECT) ||   \
                           (type == PyArray_STRING && \
                            typecode->type == PyArray_STRINGLTR) ||      \
@@ -8227,17 +8224,26 @@
                 if (PySequence_Check(op)) {
                         PyObject *thiserr;
                         /* necessary but not sufficient */
-
                         Py_INCREF(newtype);
                         r = Array_FromSequence(op, newtype, flags & FORTRAN,
-                                               min_depth, max_depth, isobject);
-                        if (r == NULL && \
-                            ((thiserr = PyErr_Occurred()) &&            \
-                             !PyErr_GivenExceptionMatches(thiserr,
-                                                          PyExc_MemoryError))) {
-                                /* It wasn't really a sequence after all.
-                                 * Try interpreting it as a scalar */
-                                PyErr_Clear();
+                                               min_depth, max_depth);
+                        if (r == NULL && (thiserr=PyErr_Occurred()) && \
+                            !PyErr_GivenExceptionMatches(thiserr, 
+                                                         PyExc_MemoryError)) {
+                                /* If object was explicitly requested, 
+                                   then try nested list object array creation
+                                */
+                                if (isobject) {
+                                        PyErr_Clear();
+                                        Py_INCREF(newtype);
+                                        r = ObjectArray_FromNestedList  \
+                                                (op, newtype, flags & FORTRAN);
+                                        seq = TRUE;
+                                        Py_DECREF(newtype);
+                                }
+                                else {
+                                        PyErr_Clear();
+                                }
                         }
                         else {
                                 seq = TRUE;

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2006-09-04 22:04:31 UTC (rev 3111)
+++ trunk/numpy/core/tests/test_regression.py	2006-09-04 22:42:18 UTC (rev 3112)
@@ -344,8 +344,8 @@
         assert_equal(N.array([[1,2],3,4],dtype=object).shape, (3,))
         assert_equal(N.array([[1,2],[3,4]],dtype=object).shape, (2,2))
         assert_equal(N.array([(1,2),(3,4)],dtype=object).shape, (2,2))
-        assert_equal(N.array([],dtype=object).shape, ())
-        assert_equal(N.array([[],[],[]],dtype=object).shape, (3,))
+        assert_equal(N.array([],dtype=object).shape, (0,))
+        assert_equal(N.array([[],[],[]],dtype=object).shape, (3,0))
         assert_equal(N.array([[3,4],[5,6],None],dtype=object).shape, (3,))
         
     def check_lexsort(self,level=rlevel):




More information about the Numpy-svn mailing list