[Numpy-discussion] PyArray_FromAny silently converts None to a singleton nan

Geoffrey Irving irving@naml...
Mon Jan 28 17:48:36 CST 2013


I discovered this from C via the PyArray_FromAny function, but here it
is in Python:

    >>> asarray(None,dtype=float)
    array(nan)

Is this expected or documented behavior?  It seems quite unintuitive
and surprising that this wouldn't throw an exception.

Is there a way to disable this behavior in PyArray_FromAny in order to
catch bugs earlier on?  In the situation where I discovered this I
actually passed None to a wrapped C routine, and it complained that it
didn't have rank 2 (since the resulting nan singleton had rank 0).
It'd be much nicer to get something mentioning NoneType.  I suppose I
could check for None manually as long there aren't any other weird
cases.

Geoffrey


More information about the NumPy-Discussion mailing list