-
Notifications
You must be signed in to change notification settings - Fork 37
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
Use pickle instead of JSON for serialization #138
Comments
You could go a step further here and use cloudpickle which would allow serializing a much wider range of objects including, for example, classes that are defined inside the notebook. cloudpickle is a common solution for interprocess communication of arbitrary objects in Python. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why can't pickle be used instead of JSON? It supports a much wider number of variable types and the advantages of JSON don't really make sense here:
As an example, I made some extra methods that I monkey patch on that have worked so var in a much wider range of possibilities than the current
value()
method provides:You can then even do
tb.get_value('_')
which will get the output of the last executed cell. I have been able to use this for numpyarray
s, PandasDataFrame
s andSerie
s, and other types as well that the JSON serialization balks at.I wouldn't add the
get_value()
method to your class, instead, I would replace all usages of JSON with pickling. I just do this to not mess with any of the methods already there.Some changes may need to be made to
ref()
since it seems to only return references to things that are not JSON serializable. It seems like it should always return a reference and not a value (the TestBookReference object would need to support more magic methods for some people though). One problem is that functions can sometimes be pickled. Sometimes unpickling them might fail even if they were pickled.The text was updated successfully, but these errors were encountered: