[Numpy-discussion] different behaviour in asfarray(None)
Charles R Harris
charlesr.harris at gmail.com
Tue Apr 22 19:51:48 EDT 2008
On Tue, Apr 22, 2008 at 4:00 PM, Travis E. Oliphant <oliphant at enthought.com>
wrote:
> Stéfan van der Walt wrote:
> > 2008/4/22 lorenzo bolla <lbolla at 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 at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080422/3615ccca/attachment.html>
More information about the NumPy-Discussion
mailing list