Python Forum
Question about deserializing some numbers (bug??)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about deserializing some numbers (bug??)
#4
It turns out that pickle.loads() starts by converting its argument to BytesIO (unless the argument is a str, see in pickle.py), and it turns out that a numpy float can be converted to a BytesIO
>>> import numpy as np
>>> thing = np.float64(0.34104)
>>> import io
>>> file = io.BytesIO(thing)
>>> file.getvalue()
b'\x88.\xa8o\x99\xd3\xd5?'
It means that pickle.loads() thinks that it receives a sequence of bytes. This leaves two questions open
  1. Shouldn't pickle.loads() check more thoroughly its arguments?
  2. Why are numpy floats convertible to BytesIO?
Reply


Messages In This Thread
RE: Question about deserializing some numbers (bug??) - by Gribouillis - Oct-27-2020, 08:19 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020