PyArray_FromAny silently converts None to a singleton nan
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
import numpy as np np.double(None) nan
On Mon, Jan 28, 2013 at 3:48 PM, Geoffrey Irving
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?
For comparison:
float32(None) nan float(None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: float() argument must be a string or a number
On Mon, Jan 28, 2013 at 5:09 PM, Bradley M. Froehle
import numpy as np np.double(None) nan
On Mon, Jan 28, 2013 at 3:48 PM, Geoffrey Irving
wrote: 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?
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Bradley M. Froehle
-
Geoffrey Irving