From 98f2a7be189b576b9b3d1c06b2ce384f5cbad6ce Mon Sep 17 00:00:00 2001 From: Chris Benson <6758792+chrisbenson32@users.noreply.github.com> Date: Tue, 28 Apr 2020 12:30:31 -0700 Subject: [PATCH] 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 --- python/fbprophet/forecaster.py | 2 +- python/fbprophet/models.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 2086b18..0622885 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -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()) diff --git a/python/fbprophet/models.py b/python/fbprophet/models.py index a6f608b..62eec97 100644 --- a/python/fbprophet/models.py +++ b/python/fbprophet/models.py @@ -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'