Hi,

I've been looking into ticket #736 and playing with some things. In
arrayobject.c starting at line 8534 I added a check for strings.

        if (PyString_Check(op)) {
            r = Array_FromPyScalar(op, newtype);
        }
        if (PySequence_Check(op)) {
            PyObject *thiserr = NULL;

            /* necessary but not sufficient */
            Py_INCREF(newtype);
            r = Array_FromSequence(op, newtype, flags & FORTRAN,
                                   min_depth, max_depth);
            if (r == NULL && (thiserr=PyErr_Occurred())) {
                if (PyErr_GivenExceptionMatches(thiserr,
                                                PyExc_MemoryError)) {
                    return NULL;
                }

I think there may be a failure to decrement the reference to newtype unless
Array_FromSequence does that (nasty side effect);

Anyway, the added check for a string fixes the conversion problem for such
things as int32('123'). There remains a problem with array('123',
dtype=int32) and with array(['123','123'], dtype=int32), but I think I can
track those down. The question is, will changing the current behavior so
that strings get converted to numbers cause problems with other programs out
there. I suspect I also need to check that strings are converted this way
only when the type is explicitly given, not detected.

Chuck
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to