From f3f4bf67ad87c4d30e3694e251d274c3b85c81da Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Mon, 9 Nov 2015 09:22:36 +0000 Subject: [PATCH] [gpyload] loading pickle with restructured kern src --- GPy/__init__.py | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/GPy/__init__.py b/GPy/__init__.py index c2b83a70..3831fa20 100644 --- a/GPy/__init__.py +++ b/GPy/__init__.py @@ -41,29 +41,22 @@ def load(file_or_path): :param file_name: path/to/file.pickle """ # This is the pickling pain when changing _src -> src + import sys + import inspect + sys.modules['GPy.kern._src'] = kern.src + for name, module in inspect.getmembers(kern.src): + if not name.startswith('_'): + sys.modules['GPy.kern._src.{}'.format(name)] = module try: - try: - import cPickle as pickle - if isinstance(file_or_path, basestring): - with open(file_or_path, 'rb') as f: - u = pickle._Unpickler(f) - u.encoding = 'latin1' - m = u.load() - else: - m = pickle.load(file_or_path) - except: - import pickle - if isinstance(file_or_path, str): - with open(file_or_path, 'rb') as f: - m = pickle.load(f) - else: - m = pickle.load(file_or_path) - except ImportError: - import sys - import inspect - sys.modules['GPy.kern._src'] = kern.src - for name, module in inspect.getmembers(kern.src): - if not name.startswith('_'): - sys.modules['GPy.kern._src.{}'.format(name)] = module - m = load(file_or_path) + import pickle + strcl = basestring + except ImportError: #python3 + import pickle + strcl = str + + if isinstance(file_or_path, strcl): + with open(file_or_path, 'rb') as f: + m = pickle.load(f) + else: + m = pickle.load(file_or_path) return m