ValueError: invalid literal for float(): -1.#IND (pickle.py)

Mark Dickinson dickinsm at gmail.com
Mon Jul 12 11:03:07 EDT 2010


Alexander Eisenhuth <newsuser <at> stacom-software.de> writes:

>    File "C:\Python25\lib\pickle.py", line 954, in load_float
>      self.append(float(self.readline()[:-1]))
> ValueError: invalid literal for float(): -1.#IND
> 
> - I'm not sure what -1.#IND means. Can somebody assist?

It's the Windows way of representing a NaN (not a number).
A NaN is typically what you get when you try to perform an
invalid floating-point operation, like taking the square root
of a negative number, or dividing 0.0 by 0.0.  Some people
also use NaNs to represent uninitialized values, or as
placeholders for missing data.

> - As pickle write the data I'm a bit confused, that is can't
> be unpickled it. Is that a bug or a feature?

Well, it's certainly not ideal.  It shouldn't be a problem in
Python 2.6 or 2.7, though;  unfortunately,  Python 2.5 is no
longer receiving bugfixes, so it's not going to change there.

> BTW: I'm tied to version 2.5 of python

Have you tried using pickle protocol 1 or 2, instead of pickle
protocol 0?  That may well solve your  problem.  (Those
protocols write out the binary form of a float directly, instead
of reading and writing a string representation.)

-- 
Mark





More information about the Python-list mailing list