Hide keyboard shortcuts

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 

3 

4 

5def save_pickle(obj, fname): 

6 """ 

7 Save the object to file via pickling. 

8 

9 Parameters 

10 ---------- 

11 fname : str 

12 Filename to pickle to 

13 """ 

14 import pickle 

15 

16 with get_file_obj(fname, 'wb') as fout: 

17 pickle.dump(obj, fout, protocol=-1) 

18 

19 

20def load_pickle(fname): 

21 """ 

22 Load a previously saved object 

23 

24 .. warning:: 

25 

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. 

29 

30 Parameters 

31 ---------- 

32 fname : str 

33 Filename to unpickle 

34 

35 Notes 

36 ----- 

37 This method can be used to load *both* models and results. 

38 """ 

39 import pickle 

40 

41 with get_file_obj(fname, 'rb') as fin: 

42 return pickle.load(fin)