[Numpy-discussion] ValueError: cannot convert float to NaN to integer

Keith Goodman kwgoodman@gmail....
Sat Jul 25 10:24:23 CDT 2009


On Wed, Jul 22, 2009 at 11:51 AM, Robert Kern<robert.kern@gmail.com> wrote:
> On Wed, Jul 22, 2009 at 13:35, Keith Goodman<kwgoodman@gmail.com> wrote:
>> On Ubuntu 9.04, python 2.6.2, numpy 1.2.1 this gives a ValueError:
>>
>> x = np.array([1,2,3])
>> x[0] = np.nan
>> ValueError: cannot convert float to NaN to integer
>>
>> But on Debian squeeze, python 2.5.4, numpy 1.2.1 the assignment works
>> (well, the float nan is convert to the int 0):
>>
>> x[0] = np.nan
>> x
>>   array([0,1,2])
>>
>> The numpy version numbers are the same. Is this a python issue?
>
> Probably. They rationalized a bunch of float behavior in Python 2.6,
> and this may be a consequence of that. grep the Python sources for
> that error message, or parts of it, to try to track down where it
> comes from.

The same error shows up when running the numpy unit tests with python
2.6 (but not with python 2.5):

======================================================================
ERROR: Tests the min/max functions with explicit outputs
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/numpy/ma/tests/test_core.py",
line 699, in test_minmax_funcs_with_output
    result = npfunc(xm,axis=0,out=nout)
  File "/usr/lib/python2.6/dist-packages/numpy/core/fromnumeric.py",
line 1569, in amin
    return amin(axis, out)
  File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 3119, in min
    np.putmask(out, newmask, np.nan)
ValueError: cannot convert float NaN to integer


More information about the NumPy-Discussion mailing list