diff --git a/python/prophet/models.py b/python/prophet/models.py index 59cde26e3..e4d7b34d2 100644 --- a/python/prophet/models.py +++ b/python/prophet/models.py @@ -228,12 +228,25 @@ def cleanup(self) -> None: if hasattr(self, "stan_fit") and self.stan_fit is not None: fit_result: cmdstanpy.CmdStanMLE | cmdstanpy.CmdStanMCMC = self.stan_fit - to_remove = ( - fit_result.runset.csv_files + - fit_result.runset.diagnostic_files + - fit_result.runset.stdout_files + - fit_result.runset.profile_files - ) + to_remove = [] + + if hasattr(fit_result, "runset"): # 1.x + to_remove = ( + fit_result.runset.csv_files # type: ignore + + fit_result.runset.diagnostic_files # type: ignore + + fit_result.runset.stdout_files # type: ignore + + fit_result.runset.profile_files # type: ignore + ) + else: # 2.0 + for attr in fit_result._FILE_ATTRS: # type: ignore + val = getattr(fit_result, attr) + if val is None: + continue + if isinstance(val, list): + to_remove.extend(val) + else: + to_remove.append(val) + for fpath in to_remove: if pathlib.Path(fpath).is_file(): pathlib.Path(fpath).unlink() diff --git a/python/pyproject.toml b/python/pyproject.toml index 8d28f128c..025b35b82 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -2,7 +2,7 @@ requires = [ "setuptools>=64", "wheel", - "cmdstanpy>=1.3.2,<2", + "cmdstanpy>=1.3.2", ] build-backend = "setuptools.build_meta" @@ -13,7 +13,7 @@ description = "Automatic Forecasting Procedure" readme = "README.md" requires-python = ">=3.10" dependencies = [ - "cmdstanpy>=1.3.2,<2", + "cmdstanpy>=1.3.2", "numpy>=1.21.6", "matplotlib>=3.5.3", "pandas>=1.3.5",