Fix Issue with Pickling Models in Python3.6 because of Logger Attribute (#1452)

* Fix issue with pickeling models due to logger

* Fixes Model Pickle Error in Python3.6 as described in #1361
This commit is contained in:
Chris Benson 2020-04-28 12:30:31 -07:00 committed by GitHub
parent 5fe3be86c5
commit 98f2a7be18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -150,7 +150,7 @@ class Prophet(object):
except Exception as e:
logger.debug("Unable to load backend %s (%s), trying the next one", i.name, e)
else:
self.stan_backend = StanBackendEnum.get_backend_class(stan_backend)(logger)
self.stan_backend = StanBackendEnum.get_backend_class(stan_backend)()
logger.debug("Loaded stan backend: %s", self.stan_backend.get_type())

View file

@ -11,14 +11,15 @@ from collections import OrderedDict
from enum import Enum
import pickle
import pkg_resources
import os
import logging
logger = logging.getLogger('fbprophet.models')
class IStanBackend(ABC):
def __init__(self, logger):
def __init__(self):
self.model = self.load_model()
self.logger = logger
self.stan_fit = None
@staticmethod
@ -82,7 +83,7 @@ class CmdStanPyBackend(IStanBackend):
except RuntimeError as e:
# Fall back on Newton
if kwargs['algorithm'] != 'Newton':
self.logger.warning(
logger.warning(
'Optimization terminated abnormally. Falling back to Newton.'
)
kwargs['algorithm'] = 'Newton'
@ -244,7 +245,7 @@ class PyStanBackend(IStanBackend):
self.stan_fit = self.model.optimizing(**args)
except RuntimeError:
# Fall back on Newton
self.logger.warning(
logger.warning(
'Optimization terminated abnormally. Falling back to Newton.'
)
args['algorithm'] = 'Newton'