[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

ValueError in pickle module during unpickling a infinite float (python 2.5.2

rehn

3/12/2008 3:22:00 PM

Unpickling an infinite float caused a ValueError in the pickle module.
I need to pickle and load infinite floats in my project. Do you have
any suggestions how to solve the issue?

# code describing the issue:

# define float constants with double-precision:

# copied from fpconst module: http://www.analytics.washington.edu/statcomp/projects/rzop...
import struct
_big_endian = struct.pack('i',1)[0] != '\x01' # check endianess
if(_big_endian): # and define appropriate constants
NaN = struct.unpack('d', '\x7F\xF8\x00\x00\x00\x00\x00\x00')[0]
PosInf = struct.unpack('d', '\x7F\xF0\x00\x00\x00\x00\x00\x00')[0]
NegInf = -PosInf
else:
NaN = struct.unpack('d', '\x00\x00\x00\x00\x00\x00\xf8\xff')[0]
PosInf = struct.unpack('d', '\x00\x00\x00\x00\x00\x00\xf0\x7f')[0]
NegInf = -PosInf


# pickling and unpickling a infinite float:

f = PosInf
p = pickle.dumps(f)
rf = pickle.loads(p)
print f
print rf

# ValueError in python 2.5.2:

Traceback (most recent call last):
File "....py", line 89, in <module>
rf = pickle.loads(p)
File "...\pickle.py", line 1374, in loads
return Unpickler(file).load()
File "...\pickle.py", line 858, in load
dispatch[key](self)
File "...\pickle.py", line 954, in load_float
self.append(float(self.readline()[:-1]))
ValueError: invalid literal for float(): 1.#INF
2 Answers

Mark Dickinson

3/12/2008 5:26:00 PM

0

On Mar 12, 11:22 am, r...@iwm.mw.tu-dresden.de wrote:
> Unpickling an infinite float caused a ValueError in the pickle module.
> I need to pickle and load infinite floats in my project. Do you have
> any suggestions how to solve the issue?

Have you tried this on the recent 2.6 alpha (Python2.6a1)? It's
available
from

http://www.python.org/download/rel...

I suspect it may already be fixed there. In any case, it would be
useful if you could file a bug report at http://bugs.....
It's not absolutely clear to me that this constitutes a bug
(though I think it does), but it would be worth having people look at
it.

I'm assuming that you're on Windows? I can't reproduce the problem
on OS X.

Mark

Peter Otten

3/12/2008 6:17:00 PM

0

rehn@iwm.mw.tu-dresden.de wrote:

> Unpickling an infinite float caused a ValueError in the pickle module.
> I need to pickle and load infinite floats in my project. Do you have
> any suggestions how to solve the issue?

You could try another protocol. Does

>>> inf = 1e1000
>>> pickle.loads(pickle.dumps(inf, pickle.HIGHEST_PROTOCOL))
inf

work?

Peter