mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-20 09:03:39 +00:00
Migrate pkg_resources to importlib_resources (#2352)
This commit is contained in:
parent
0bf05baf3c
commit
3c5321681a
2 changed files with 10 additions and 15 deletions
|
|
@ -9,8 +9,7 @@ from abc import abstractmethod, ABC
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
import importlib_resources
|
||||||
import pkg_resources
|
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -59,11 +58,9 @@ class CmdStanPyBackend(IStanBackend):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
import cmdstanpy
|
import cmdstanpy
|
||||||
# this must be set before super.__init__() for load_model to work on Windows
|
# this must be set before super.__init__() for load_model to work on Windows
|
||||||
local_cmdstan = pkg_resources.resource_filename(
|
local_cmdstan = importlib_resources.files("prophet") / "stan_model" / f"cmdstan-{self.CMDSTAN_VERSION}"
|
||||||
"prophet", f"stan_model/cmdstan-{self.CMDSTAN_VERSION}"
|
if local_cmdstan.exists():
|
||||||
)
|
cmdstanpy.set_cmdstan_path(str(local_cmdstan))
|
||||||
if Path(local_cmdstan).exists():
|
|
||||||
cmdstanpy.set_cmdstan_path(local_cmdstan)
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -72,11 +69,8 @@ class CmdStanPyBackend(IStanBackend):
|
||||||
|
|
||||||
def load_model(self):
|
def load_model(self):
|
||||||
import cmdstanpy
|
import cmdstanpy
|
||||||
model_file = pkg_resources.resource_filename(
|
model_file = importlib_resources.files("prophet") / "stan_model" / "prophet_model.bin"
|
||||||
'prophet',
|
return cmdstanpy.CmdStanModel(exe_file=str(model_file))
|
||||||
'stan_model/prophet_model.bin',
|
|
||||||
)
|
|
||||||
return cmdstanpy.CmdStanModel(exe_file=model_file)
|
|
||||||
|
|
||||||
def fit(self, stan_init, stan_data, **kwargs):
|
def fit(self, stan_init, stan_data, **kwargs):
|
||||||
if 'inits' not in kwargs and 'init' in kwargs:
|
if 'inits' not in kwargs and 'init' in kwargs:
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ dependencies = [
|
||||||
"holidays>=0.14.2",
|
"holidays>=0.14.2",
|
||||||
"python-dateutil>=2.8.0",
|
"python-dateutil>=2.8.0",
|
||||||
"tqdm>=4.36.1",
|
"tqdm>=4.36.1",
|
||||||
|
"importlib_resources",
|
||||||
]
|
]
|
||||||
authors = [
|
authors = [
|
||||||
{name = "Sean J. Taylor", email = "sjtz@pm.me"},
|
{name = "Sean J. Taylor", email = "sjtz@pm.me"},
|
||||||
|
|
@ -56,6 +57,6 @@ parallel = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
homepage = "https://facebook.github.io/prophet/"
|
Homepage = "https://facebook.github.io/prophet/"
|
||||||
documentation = "https://facebook.github.io/prophet/"
|
Documentation = "https://facebook.github.io/prophet/"
|
||||||
repository = "https://github.com/facebook/prophet"
|
Repository = "https://github.com/facebook/prophet"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue