New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about deserializing some numbers (bug??) #86334
Comments
Hi! In order to deserialize bytes object, we use pickle.loads(): import pickle
import numpy as np
pickle.loads(np.float64(0.34103)) and the expected result is like below (because np.float64(0.34103) is not bytes objects, appropriate errors are expected) UnpicklingError Traceback (most recent call last)
<ipython-input-19-5c07606a60f1> in <module>
----> 1 pickle.loads(np.float64(0.34103)) UnpicklingError: invalid load key, '\xc1'. Here we have some questions that some numbers (it is rare) like 0.34104 prints the following result without errors. This occurs only when the converted bytes start with b'\x88 (for example 0.04263, 0.08526, 0.11651 ...) Any answer will be highly appreciated. |
Can anyone explain "pickle.loads(np.float64(0.34104))" prints "True"? |
I explained this in https://bugs.python.org/issue42165#msg379755 This is not a bug in python, it's a bug in your code. You should not expect to unpickle something that wasn't created by pickling it. |
Or stated differently: if you pass random byte strings to pickle.loads(), sometimes it might succeed and produce a random object because you've managed to create a valid pickle. But most often it will fail. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: