Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/statsmodels/iolib/smpickle.py : 33%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Helper files for pickling"""
2from statsmodels.iolib.openfile import get_file_obj
5def save_pickle(obj, fname):
6 """
7 Save the object to file via pickling.
9 Parameters
10 ----------
11 fname : str
12 Filename to pickle to
13 """
14 import pickle
16 with get_file_obj(fname, 'wb') as fout:
17 pickle.dump(obj, fout, protocol=-1)
20def load_pickle(fname):
21 """
22 Load a previously saved object
24 .. warning::
26 Loading pickled models is not secure against erroneous or maliciously
27 constructed data. Never unpickle data received from an untrusted or
28 unauthenticated source.
30 Parameters
31 ----------
32 fname : str
33 Filename to unpickle
35 Notes
36 -----
37 This method can be used to load *both* models and results.
38 """
39 import pickle
41 with get_file_obj(fname, 'rb') as fin:
42 return pickle.load(fin)