summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-09-04 22:42:18 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-09-04 22:42:18 +0000
commit9c736b3941cf35d395524b0416deb4a462ef4a9b (patch)
treea8c93d841b732baf03e83716383a24772788c6f1
parent0982d6e124e0728e227bda735a19c359900fcc4a (diff)
downloadnumpy-9c736b3941cf35d395524b0416deb4a462ef4a9b.tar.gz
Fix object array creation to revert to previous behavior
-rw-r--r--numpy/core/src/arrayobject.c32
-rw-r--r--numpy/core/tests/test_regression.py4
2 files changed, 21 insertions, 15 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 316dc57cd..0d253ee2a 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -7146,7 +7146,7 @@ ObjectArray_FromNestedList(PyObject *s, PyArray_Descr *typecode, int fortran)
/* 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 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
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 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
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;
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index faf0dcd3b..c13eccb28 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -344,8 +344,8 @@ class test_regression(NumpyTestCase):
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):