[Numpy-discussion] different behaviour in asfarray(None)
Charles R Harris
charlesr.harris@gmail....
Tue Apr 22 18:51:48 CDT 2008
On Tue, Apr 22, 2008 at 4:00 PM, Travis E. Oliphant <oliphant@enthought.com>
wrote:
> Stéfan van der Walt wrote:
> > 2008/4/22 lorenzo bolla <lbolla@gmail.com>:
> >
> >> I noticed a change in the behaviour of numpy.asfarray between numpy
> version
> >> 1.0.5 and 1.1.0:
> >>
> >> 1.0.5
> >> ====
> >>
> >> In [3]: numpy.asfarray(None)
> >> Out[3]: array(nan)
> >> In [4]: numpy.__version__
> >> Out[4]: '1.0.5.dev4455'
> >>
> >> 1.1.0
> >> ====
> >>
> >> In [16]: numpy.asfarray(None)
> >>
> ---------------------------------------------------------------------------
> >> <type 'exceptions.TypeError'>: float() argument must be a string or a
> number
> >>
> >> Is this intended? why?
> >>
> >
> > Yes, 'asfarray' is equivalent to
> >
> > array(input).astype(dtype)
> >
> > I think it would be wrong to assume that None means NaN.
> >
> I'm curious who made the change and why. There was code intentionally
> there to interpret None as nan for float arrays. So, I don't
> understand why and/or when it changed.
>
Could be here:
static double
MyPyFloat_AsDouble(PyObject *obj)
{
double ret = 0;
PyObject *num = PyNumber_Float(obj);
if (num == NULL) {
return _getNAN();
}
ret = PyFloat_AsDouble(num);
Py_DECREF(num);
return ret;
}
I don't know what PyNumber_Float does with None. I suspect all we need to do
is call PyErr_Clear() in the if. The change was made so floats could be
passed as strings.
Chuck
>
> -Travis
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080422/3615ccca/attachment.html
More information about the Numpy-discussion
mailing list