Oct-27-2020, 08:19 PM
(This post was last modified: Oct-27-2020, 08:22 PM by Gribouillis.)
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
- Shouldn't pickle.loads() check more thoroughly its arguments?
- Why are numpy floats convertible to BytesIO?