I’m following along with Chapter 9, and have reached the point where we’re persisting our instance of TabularPandas
to a Pickle file:
to = TabularPandas(df, procs, cat, cont, y_names=dep_var, splits=splits)
save_pickle(path/'to.pkl',to)
This all works fine. The problem happens when I try to use the provided example code to read the Pickle file into memory:
to = (path/'to.pkl').load()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-44-e1b539368431> in <module>
----> 1 to = (path/'to.pkl').load()
AttributeError: 'PosixPath' object has no attribute 'load'
I ran help(path/'to.pkl')
to see if there is in fact a load()
method on the PosixPath class, and I didn’t find one. I also checked the docs, and didn’t find one there either.
After a bit of research, I found this article, which talks about how to Pickle and un-Pickle scalars and objects in Python. This was educational, and I attempted to import the pickle
library and run pickle.load(path/'to.pkl')
, but got a new error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-46-178322946f3f> in <module>
----> 1 to = pickle.load(path/'to.pkl')
TypeError: file must have 'read' and 'readline' attributes
This is strange since I’ve verified that the path is in fact a file:
os.path.isfile(path/'to.pkl')
True
os.path.isdir(path/'to.pkl')
False
I feel like this chapter is unlikely to be wrong since it has been read and re-read many times by this point. I’m sure I’m missing something, I just don’t know what it is. Anybody see what I’m doing wrong?