[issue42165] closed (reopen with other issue)
Eric V. Smith
report at bugs.python.org
Tue Oct 27 08:27:15 EDT 2020
Eric V. Smith <eric at trueblade.com> added the comment:
To answer the question:
> "can anyone explain why "pickle.loads(np.float64(0.34104))" prints "True"
You can use pickletools.dis:
>>> bytes(np.float64(0.34104))
b'\x88.\xa8o\x99\xd3\xd5?'
>>> pickletools.dis(bytes(np.float64(0.34104)))
0: \x88 NEWTRUE
1: . STOP
Note that pickle ignores anything after the end of the pickle (the STOP opcode), so only the first 2 bytes are being used.
As Serhiy said, it's just chance that the bytes returned by numpy happen to be a valid pickle for some values. You should not be trying to .loads() something that isn't a valid pickle stream. It's not clear why you think a byte string returned by np.float64 would be a valid pickle.
----------
nosy: +eric.smith
stage: resolved ->
status: closed -> open
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42165>
_______________________________________
More information about the Python-bugs-list
mailing list