From cf598e047c259a5d27dc252d60bdc26fad2eacfb Mon Sep 17 00:00:00 2001 From: edwinnglabs Date: Thu, 15 Feb 2024 19:05:12 -0800 Subject: [PATCH] fix lint with isort --- docs/conf.py | 2 ++ orbit/constants/palette.py | 3 +- orbit/diagnostics/backtest.py | 18 +++++----- orbit/diagnostics/plot.py | 21 ++++++------ orbit/eda/eda_plot.py | 5 +-- orbit/estimators/base_estimator.py | 1 + orbit/estimators/pyro_estimator.py | 8 ++--- orbit/estimators/stan_estimator.py | 9 +++-- orbit/forecaster/__init__.py | 4 +-- orbit/forecaster/forecaster.py | 17 +++++----- orbit/forecaster/full_bayes.py | 7 ++-- orbit/forecaster/map.py | 7 ++-- orbit/forecaster/svi.py | 7 ++-- orbit/models/__init__.py | 6 ++-- orbit/models/dlt.py | 6 ++-- orbit/models/ets.py | 6 ++-- orbit/models/ktr.py | 8 ++--- orbit/models/ktrlite.py | 8 ++--- orbit/models/lgt.py | 6 ++-- orbit/pyro/ktr.py | 4 +-- orbit/pyro/lgt.py | 3 +- orbit/template/dlt.py | 24 ++++++------- orbit/template/ets.py | 14 ++++---- orbit/template/ktr.py | 34 +++++++++---------- orbit/template/ktrlite.py | 28 +++++++-------- orbit/template/lgt.py | 31 +++++++---------- orbit/utils/dataset.py | 5 +-- orbit/utils/features.py | 1 + orbit/utils/general.py | 5 +-- orbit/utils/knots.py | 1 + orbit/utils/params_tuning.py | 12 +++---- orbit/utils/plot.py | 3 +- orbit/utils/simulation.py | 6 ++-- orbit/utils/stan.py | 5 +-- setup.py | 13 +++---- tests/conftest.py | 12 ++++--- tests/orbit/diagnostics/test_backtest.py | 8 ++--- tests/orbit/diagnostics/test_eda_plot.py | 2 +- tests/orbit/diagnostics/test_plot.py | 15 ++++---- tests/orbit/diagnostics/test_wbic.py | 4 +-- tests/orbit/estimators/test_stan_estimator.py | 2 +- tests/orbit/models/test_dlt.py | 5 +-- tests/orbit/models/test_ets.py | 7 ++-- tests/orbit/models/test_ktr.py | 4 +-- tests/orbit/models/test_ktrlite.py | 4 +-- tests/orbit/models/test_lgt.py | 5 +-- tests/orbit/utils/test_knots.py | 5 +-- 47 files changed, 209 insertions(+), 202 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a62e3d83..c2ac7f29 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,10 +12,12 @@ import os import sys + import sphinx_rtd_theme sys.path.insert(0, os.path.abspath("..")) import matplotlib + import orbit # -- Project information ----------------------------------------------------- diff --git a/orbit/constants/palette.py b/orbit/constants/palette.py index 68708b05..d99d160d 100644 --- a/orbit/constants/palette.py +++ b/orbit/constants/palette.py @@ -1,6 +1,7 @@ from enum import Enum -import seaborn as sns + import matplotlib.colors as clr +import seaborn as sns class KTRPalette(Enum): diff --git a/orbit/diagnostics/backtest.py b/orbit/diagnostics/backtest.py index 6736cbeb..ca2c79f4 100644 --- a/orbit/diagnostics/backtest.py +++ b/orbit/diagnostics/backtest.py @@ -1,15 +1,17 @@ -import pandas as pd -import numpy as np -import matplotlib.pyplot as plt -from copy import deepcopy import inspect +from copy import deepcopy + +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd -from .metrics import smape, wmape, mape, mse, mae, rmsse -from ..exceptions import BacktestException -from ..constants.constants import TimeSeriesSplitSchemeKeys, BacktestFitKeys -from ..constants.palette import OrbitPalette as OrbitPal from orbit.utils.plot import orbit_style_decorator +from ..constants.constants import BacktestFitKeys, TimeSeriesSplitSchemeKeys +from ..constants.palette import OrbitPalette as OrbitPal +from ..exceptions import BacktestException +from .metrics import mae, mape, mse, rmsse, smape, wmape + class TimeSeriesSplitter(object): """Cross validation splitter for time series data""" diff --git a/orbit/diagnostics/plot.py b/orbit/diagnostics/plot.py index 261edd2d..fe276bce 100644 --- a/orbit/diagnostics/plot.py +++ b/orbit/diagnostics/plot.py @@ -1,27 +1,26 @@ # the following lines are added to fix unit test error # or else the following line will give the following error # TclError: no display name and no $DISPLAY environment variable -import matplotlib.pyplot as plt -import seaborn as sns -import pandas as pd -import numpy as np +import logging import math import os + +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd import pkg_resources +import seaborn as sns import statsmodels.api as sm from scipy import stats -from ..constants.constants import PredictionKeys -from orbit.utils.general import is_empty_dataframe, is_ordered_datetime -from ..constants.constants import BacktestFitKeys -from ..constants.palette import PredictionPaletteClassic as PredPal from orbit.constants import palette from orbit.diagnostics.metrics import smape +from orbit.utils.general import is_empty_dataframe, is_ordered_datetime from orbit.utils.plot import orbit_style_decorator -from ..exceptions import PlotException - -import logging +from ..constants.constants import BacktestFitKeys, PredictionKeys +from ..constants.palette import PredictionPaletteClassic as PredPal +from ..exceptions import PlotException logger = logging.getLogger("orbit") diff --git a/orbit/eda/eda_plot.py b/orbit/eda/eda_plot.py index 233668b7..627ad9ad 100644 --- a/orbit/eda/eda_plot.py +++ b/orbit/eda/eda_plot.py @@ -1,7 +1,8 @@ +import math + +import pandas as pd import seaborn as sns from matplotlib import pyplot as plt -import pandas as pd -import math from orbit.constants import palette from orbit.utils.plot import orbit_style_decorator diff --git a/orbit/estimators/base_estimator.py b/orbit/estimators/base_estimator.py index 588ac27c..355db50d 100644 --- a/orbit/estimators/base_estimator.py +++ b/orbit/estimators/base_estimator.py @@ -1,4 +1,5 @@ from abc import abstractmethod + import numpy as np # from ..utils.docstring_style import merge_numpy_docs_dedup diff --git a/orbit/estimators/pyro_estimator.py b/orbit/estimators/pyro_estimator.py index 4ac88bf2..d1676d54 100644 --- a/orbit/estimators/pyro_estimator.py +++ b/orbit/estimators/pyro_estimator.py @@ -1,15 +1,15 @@ -from abc import abstractmethod -import numpy as np import logging +from abc import abstractmethod +import numpy as np import pyro from pyro.infer import SVI, Trace_ELBO -from pyro.infer.autoguide import AutoLowRankMultivariateNormal, AutoDelta +from pyro.infer.autoguide import AutoDelta, AutoLowRankMultivariateNormal from pyro.optim import ClippedAdam -from .base_estimator import BaseEstimator from ..exceptions import EstimatorException from ..utils.pyro import get_pyro_model +from .base_estimator import BaseEstimator logger = logging.getLogger("orbit") diff --git a/orbit/estimators/stan_estimator.py b/orbit/estimators/stan_estimator.py index dae83548..ed0fa8f1 100644 --- a/orbit/estimators/stan_estimator.py +++ b/orbit/estimators/stan_estimator.py @@ -1,15 +1,14 @@ -from abc import abstractmethod -from copy import copy import logging import multiprocessing +from abc import abstractmethod +from copy import copy from sys import platform, version_info -from .base_estimator import BaseEstimator from ..exceptions import EstimatorException -from ..utils.stan import get_compiled_stan_model, suppress_stdout_stderr from ..utils.general import update_dict from ..utils.logger import get_logger - +from ..utils.stan import get_compiled_stan_model, suppress_stdout_stderr +from .base_estimator import BaseEstimator logger = get_logger("orbit") diff --git a/orbit/forecaster/__init__.py b/orbit/forecaster/__init__.py index 08fa8afc..856fd8d3 100644 --- a/orbit/forecaster/__init__.py +++ b/orbit/forecaster/__init__.py @@ -1,4 +1,4 @@ +from .forecaster import * +from .full_bayes import * from .map import * from .svi import * -from .full_bayes import * -from .forecaster import * diff --git a/orbit/forecaster/forecaster.py b/orbit/forecaster/forecaster.py index 9ca2c223..2fa534f6 100644 --- a/orbit/forecaster/forecaster.py +++ b/orbit/forecaster/forecaster.py @@ -1,16 +1,17 @@ -from copy import deepcopy -import numpy as np -import pandas as pd import warnings +from copy import deepcopy from enum import Enum +from typing import Any, Dict -from typing import Dict, Any +import numpy as np +import pandas as pd -from ..exceptions import ForecasterException, AbstractMethodException, IllegalArgument -from ..utils.general import is_ordered_datetime, is_even_gap_datetime -from ..template.model_template import ModelTemplate +from ..constants.constants import PredictionMetaKeys, TrainingMetaKeys from ..estimators.stan_estimator import StanEstimatorMCMC -from ..constants.constants import TrainingMetaKeys, PredictionMetaKeys +from ..exceptions import (AbstractMethodException, ForecasterException, + IllegalArgument) +from ..template.model_template import ModelTemplate +from ..utils.general import is_even_gap_datetime, is_ordered_datetime COMMON_MODEL_CALLABLES = [ "get_data_input_mapper", diff --git a/orbit/forecaster/full_bayes.py b/orbit/forecaster/full_bayes.py index 809fba10..d4fd4d50 100644 --- a/orbit/forecaster/full_bayes.py +++ b/orbit/forecaster/full_bayes.py @@ -1,10 +1,11 @@ +from functools import partial + import numpy as np import pandas as pd -from functools import partial -from ..constants.constants import PredictMethod, PredictionKeys +from ..constants.constants import PredictionKeys, PredictMethod from ..exceptions import ForecasterException -from ..utils.predictions import prepend_date_column, compute_percentiles +from ..utils.predictions import compute_percentiles, prepend_date_column from .forecaster import Forecaster diff --git a/orbit/forecaster/map.py b/orbit/forecaster/map.py index 7c28bd77..33bc02c4 100644 --- a/orbit/forecaster/map.py +++ b/orbit/forecaster/map.py @@ -1,10 +1,11 @@ +from functools import partial + import numpy as np import pandas as pd -from functools import partial -from ..constants.constants import PredictMethod, PredictionKeys +from ..constants.constants import PredictionKeys, PredictMethod from ..exceptions import ForecasterException -from ..utils.predictions import prepend_date_column, compute_percentiles +from ..utils.predictions import compute_percentiles, prepend_date_column from .forecaster import Forecaster diff --git a/orbit/forecaster/svi.py b/orbit/forecaster/svi.py index 67f4cf01..68033118 100644 --- a/orbit/forecaster/svi.py +++ b/orbit/forecaster/svi.py @@ -1,10 +1,11 @@ +from functools import partial + import numpy as np import pandas as pd -from functools import partial -from ..constants.constants import PredictMethod, PredictionKeys +from ..constants.constants import PredictionKeys, PredictMethod from ..exceptions import ForecasterException -from ..utils.predictions import prepend_date_column, compute_percentiles +from ..utils.predictions import compute_percentiles, prepend_date_column from .forecaster import Forecaster diff --git a/orbit/models/__init__.py b/orbit/models/__init__.py index b8c8631d..f815dd1e 100644 --- a/orbit/models/__init__.py +++ b/orbit/models/__init__.py @@ -1,5 +1,5 @@ -from .ets import ETS -from .lgt import LGT from .dlt import DLT -from .ktrlite import KTRLite +from .ets import ETS from .ktr import KTR +from .ktrlite import KTRLite +from .lgt import LGT diff --git a/orbit/models/dlt.py b/orbit/models/dlt.py index d8fecf81..459de8d1 100644 --- a/orbit/models/dlt.py +++ b/orbit/models/dlt.py @@ -1,8 +1,8 @@ # from inspect import signature -from ..template.dlt import DLTModel -from ..forecaster import MAPForecaster, FullBayesianForecaster -from ..exceptions import IllegalArgument from ..constants.constants import EstimatorsKeys +from ..exceptions import IllegalArgument +from ..forecaster import FullBayesianForecaster, MAPForecaster +from ..template.dlt import DLTModel def DLT( diff --git a/orbit/models/ets.py b/orbit/models/ets.py index 66258698..f044545b 100644 --- a/orbit/models/ets.py +++ b/orbit/models/ets.py @@ -1,8 +1,8 @@ # from inspect import signature -from ..template.ets import ETSModel -from ..forecaster import MAPForecaster, FullBayesianForecaster -from ..exceptions import IllegalArgument from ..constants.constants import EstimatorsKeys +from ..exceptions import IllegalArgument +from ..forecaster import FullBayesianForecaster, MAPForecaster +from ..template.ets import ETSModel def ETS( diff --git a/orbit/models/ktr.py b/orbit/models/ktr.py index 984fcc3c..405396af 100644 --- a/orbit/models/ktr.py +++ b/orbit/models/ktr.py @@ -1,8 +1,8 @@ -from ..template.ktr import KTRModel -from ..forecaster import SVIForecaster -from ..exceptions import IllegalArgument -from ..estimators.pyro_estimator import PyroEstimatorSVI from ..constants.constants import EstimatorsKeys +from ..estimators.pyro_estimator import PyroEstimatorSVI +from ..exceptions import IllegalArgument +from ..forecaster import SVIForecaster +from ..template.ktr import KTRModel def KTR( diff --git a/orbit/models/ktrlite.py b/orbit/models/ktrlite.py index 2ede7cb1..690ea648 100644 --- a/orbit/models/ktrlite.py +++ b/orbit/models/ktrlite.py @@ -1,8 +1,8 @@ -from ..template.ktrlite import KTRLiteModel -from ..forecaster import MAPForecaster -from ..exceptions import IllegalArgument -from ..estimators.stan_estimator import StanEstimatorMAP from ..constants.constants import EstimatorsKeys +from ..estimators.stan_estimator import StanEstimatorMAP +from ..exceptions import IllegalArgument +from ..forecaster import MAPForecaster +from ..template.ktrlite import KTRLiteModel def KTRLite( diff --git a/orbit/models/lgt.py b/orbit/models/lgt.py index 9c2051ba..666c3521 100644 --- a/orbit/models/lgt.py +++ b/orbit/models/lgt.py @@ -1,8 +1,8 @@ # from inspect import signature -from ..template.lgt import LGTModel -from ..forecaster import MAPForecaster, FullBayesianForecaster, SVIForecaster -from ..exceptions import IllegalArgument from ..constants.constants import EstimatorsKeys +from ..exceptions import IllegalArgument +from ..forecaster import FullBayesianForecaster, MAPForecaster, SVIForecaster +from ..template.lgt import LGTModel def LGT( diff --git a/orbit/pyro/ktr.py b/orbit/pyro/ktr.py index 68c08e09..6f80a89c 100644 --- a/orbit/pyro/ktr.py +++ b/orbit/pyro/ktr.py @@ -1,9 +1,7 @@ import numpy as np -import torch - import pyro import pyro.distributions as dist - +import torch # FIXME: this is sort of dangerous; consider better implementation later torch.set_default_tensor_type("torch.DoubleTensor") diff --git a/orbit/pyro/lgt.py b/orbit/pyro/lgt.py index ffdba22f..cee75d95 100644 --- a/orbit/pyro/lgt.py +++ b/orbit/pyro/lgt.py @@ -1,8 +1,7 @@ import numpy as np -import torch - import pyro import pyro.distributions as dist +import torch torch.set_default_tensor_type("torch.DoubleTensor") diff --git a/orbit/template/dlt.py b/orbit/template/dlt.py index 40c4be88..bd3a24cb 100644 --- a/orbit/template/dlt.py +++ b/orbit/template/dlt.py @@ -1,23 +1,19 @@ +from copy import deepcopy +from enum import Enum + import numpy as np import pandas as pd -from scipy.stats import nct -from copy import deepcopy import torch -from enum import Enum +from scipy.stats import nct -from ..constants.constants import ( - DEFAULT_REGRESSOR_SIGN, - DEFAULT_REGRESSOR_BETA, - DEFAULT_REGRESSOR_SIGMA, - COEFFICIENT_DF_COLS, - PredictMethod, - PredictionKeys, - TrainingMetaKeys, - PredictionMetaKeys, -) +from ..constants.constants import (COEFFICIENT_DF_COLS, DEFAULT_REGRESSOR_BETA, + DEFAULT_REGRESSOR_SIGMA, + DEFAULT_REGRESSOR_SIGN, PredictionKeys, + PredictionMetaKeys, PredictMethod, + TrainingMetaKeys) +from ..estimators.stan_estimator import StanEstimatorMAP, StanEstimatorMCMC from ..exceptions import IllegalArgument, ModelException, PredictionException from .ets import ETSModel -from ..estimators.stan_estimator import StanEstimatorMCMC, StanEstimatorMAP class DataInputMapper(Enum): diff --git a/orbit/template/ets.py b/orbit/template/ets.py index e205b71a..a7d14bdc 100644 --- a/orbit/template/ets.py +++ b/orbit/template/ets.py @@ -1,13 +1,15 @@ -import numpy as np from copy import deepcopy -import torch from enum import Enum -from ..constants.constants import PredictionKeys, TrainingMetaKeys, PredictionMetaKeys -from ..exceptions import IllegalArgument, DataInputException -from .model_template import ModelTemplate -from ..estimators.stan_estimator import StanEstimatorMCMC, StanEstimatorMAP +import numpy as np +import torch + +from ..constants.constants import (PredictionKeys, PredictionMetaKeys, + TrainingMetaKeys) +from ..estimators.stan_estimator import StanEstimatorMAP, StanEstimatorMCMC +from ..exceptions import DataInputException, IllegalArgument from ..utils.features import moving_average +from .model_template import ModelTemplate # constants for attributes, params and I/Os diff --git a/orbit/template/ktr.py b/orbit/template/ktr.py index 85d1ae1c..72e7a870 100644 --- a/orbit/template/ktr.py +++ b/orbit/template/ktr.py @@ -1,29 +1,27 @@ -from orbit.models.ktrlite import KTRLite -import pandas as pd -import numpy as np import math -from scipy.stats import nct +from copy import deepcopy from enum import Enum -import torch + import matplotlib.pyplot as plt -from copy import deepcopy +import numpy as np +import pandas as pd +import torch +from scipy.stats import nct -from ..constants.constants import ( - KTRTimePointPriorKeys, - PredictMethod, - TrainingMetaKeys, - PredictionMetaKeys, -) +from orbit.constants.palette import OrbitPalette +from orbit.models.ktrlite import KTRLite + +from ..constants.constants import (KTRTimePointPriorKeys, PredictionMetaKeys, + PredictMethod, TrainingMetaKeys) +from ..estimators.pyro_estimator import PyroEstimatorSVI from ..exceptions import IllegalArgument, ModelException, PredictionException +from ..models import KTRLite +from ..utils.features import make_seasonal_regressors from ..utils.general import is_ordered_datetime from ..utils.kernels import gauss_kernel, sandwich_kernel -from ..utils.features import make_seasonal_regressors -from .model_template import ModelTemplate -from ..estimators.pyro_estimator import PyroEstimatorSVI -from ..models import KTRLite -from orbit.constants.palette import OrbitPalette -from ..utils.knots import get_knot_idx, get_knot_dates +from ..utils.knots import get_knot_dates, get_knot_idx from ..utils.plot import orbit_style_decorator +from .model_template import ModelTemplate class DataInputMapper(Enum): diff --git a/orbit/template/ktrlite.py b/orbit/template/ktrlite.py index ce02e56a..a5d1b4c0 100644 --- a/orbit/template/ktrlite.py +++ b/orbit/template/ktrlite.py @@ -1,26 +1,24 @@ +import math +from copy import deepcopy +from enum import Enum + +import matplotlib.pyplot as plt import numpy as np import pandas as pd -from copy import deepcopy import torch -from enum import Enum -import math from scipy.stats import nct -import matplotlib.pyplot as plt -from ..constants.constants import ( - PredictionKeys, - PredictMethod, - TrainingMetaKeys, - PredictionMetaKeys, -) -from ..exceptions import IllegalArgument, ModelException -from .model_template import ModelTemplate +from orbit.constants.palette import OrbitPalette + +from ..constants.constants import (PredictionKeys, PredictionMetaKeys, + PredictMethod, TrainingMetaKeys) from ..estimators.stan_estimator import StanEstimatorMAP -from ..utils.kernels import sandwich_kernel +from ..exceptions import IllegalArgument, ModelException from ..utils.features import make_fourier_series_df -from orbit.constants.palette import OrbitPalette -from ..utils.knots import get_knot_idx, get_knot_dates +from ..utils.kernels import sandwich_kernel +from ..utils.knots import get_knot_dates, get_knot_idx from ..utils.plot import orbit_style_decorator +from .model_template import ModelTemplate class DataInputMapper(Enum): diff --git a/orbit/template/lgt.py b/orbit/template/lgt.py index d28f3b25..deec7e12 100644 --- a/orbit/template/lgt.py +++ b/orbit/template/lgt.py @@ -1,27 +1,22 @@ -import numpy as np -import pandas as pd -from scipy.stats import nct +import warnings from copy import deepcopy -import torch from enum import Enum -import warnings -from ..constants.constants import ( - DEFAULT_REGRESSOR_SIGN, - DEFAULT_REGRESSOR_BETA, - DEFAULT_REGRESSOR_SIGMA, - COEFFICIENT_DF_COLS, - PredictMethod, - PredictionKeys, - TrainingMetaKeys, - PredictionMetaKeys, -) -from ..exceptions import IllegalArgument, ModelException, DataInputException +import numpy as np +import pandas as pd +import torch +from scipy.stats import nct +from ..constants.constants import (COEFFICIENT_DF_COLS, DEFAULT_REGRESSOR_BETA, + DEFAULT_REGRESSOR_SIGMA, + DEFAULT_REGRESSOR_SIGN, PredictionKeys, + PredictionMetaKeys, PredictMethod, + TrainingMetaKeys) +from ..estimators.pyro_estimator import PyroEstimatorSVI +from ..estimators.stan_estimator import StanEstimatorMAP, StanEstimatorMCMC +from ..exceptions import DataInputException, IllegalArgument, ModelException # from .model_template import ModelTemplate from .ets import ETSModel -from ..estimators.stan_estimator import StanEstimatorMCMC, StanEstimatorMAP -from ..estimators.pyro_estimator import PyroEstimatorSVI class DataInputMapper(Enum): diff --git a/orbit/utils/dataset.py b/orbit/utils/dataset.py index 374678af..2e9b63ca 100644 --- a/orbit/utils/dataset.py +++ b/orbit/utils/dataset.py @@ -1,7 +1,8 @@ -import pandas as pd -import numpy as np from datetime import datetime +import numpy as np +import pandas as pd + def load_iclaims(end_date="2018-06-24", transform=True): """Load iclaims dataset diff --git a/orbit/utils/features.py b/orbit/utils/features.py index 9248885b..8ae42bd6 100644 --- a/orbit/utils/features.py +++ b/orbit/utils/features.py @@ -1,5 +1,6 @@ import numpy as np import pandas as pd + from orbit.exceptions import IllegalArgument diff --git a/orbit/utils/general.py b/orbit/utils/general.py index cb7d15f4..f2c24ff2 100644 --- a/orbit/utils/general.py +++ b/orbit/utils/general.py @@ -1,9 +1,10 @@ import os -import numpy as np -import pandas as pd from copy import deepcopy from itertools import product +import numpy as np +import pandas as pd + def update_dict(original_dict, append_dict): new_dict = deepcopy(original_dict) diff --git a/orbit/utils/knots.py b/orbit/utils/knots.py index 53f92787..ab73b91e 100644 --- a/orbit/utils/knots.py +++ b/orbit/utils/knots.py @@ -1,5 +1,6 @@ import numpy as np import pandas as pd + from ..exceptions import IllegalArgument diff --git a/orbit/utils/params_tuning.py b/orbit/utils/params_tuning.py index 1a462d91..c6ed09f1 100644 --- a/orbit/utils/params_tuning.py +++ b/orbit/utils/params_tuning.py @@ -1,16 +1,16 @@ -import pandas as pd import inspect -from tqdm.auto import tqdm +import logging +from collections.abc import Iterable, Mapping from itertools import product -from collections.abc import Mapping, Iterable -from ..diagnostics.metrics import smape +import pandas as pd +from tqdm.auto import tqdm + from ..diagnostics.backtest import BackTester +from ..diagnostics.metrics import smape from ..exceptions import IllegalArgument from ..forecaster import MAPForecaster -import logging - logger = logging.getLogger("orbit") diff --git a/orbit/utils/plot.py b/orbit/utils/plot.py index 001c9400..27603a1e 100644 --- a/orbit/utils/plot.py +++ b/orbit/utils/plot.py @@ -1,6 +1,7 @@ -import pkg_resources import functools import logging + +import pkg_resources from matplotlib import pyplot as plt STYLE_FILE_NAME = "plot_style" diff --git a/orbit/utils/simulation.py b/orbit/utils/simulation.py index cb628c6a..635e4680 100644 --- a/orbit/utils/simulation.py +++ b/orbit/utils/simulation.py @@ -1,8 +1,10 @@ +import math +from math import pi + import numpy as np import pandas as pd from statsmodels.tsa.arima_process import ArmaProcess -import math -from math import pi + from orbit.exceptions import IllegalArgument diff --git a/orbit/utils/stan.py b/orbit/utils/stan.py index 746f9214..6c3c33a7 100644 --- a/orbit/utils/stan.py +++ b/orbit/utils/stan.py @@ -1,11 +1,12 @@ +import os import pickle # import pkg_resources import importlib_resources - -import os from cmdstanpy import CmdStanModel + from orbit.constants.constants import CompiledStanModelPath + from ..utils.logger import get_logger logger = get_logger("orbit") diff --git a/setup.py b/setup.py index 5a2d6114..954628e5 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,15 @@ -import sys import os import platform -from pathlib import Path +import sys import tempfile +from pathlib import Path from shutil import copy, copytree, rmtree -from setuptools import setup, find_packages, Extension -from setuptools.command.build_py import build_py -from setuptools.command.test import test as test_command +from setuptools import Extension, find_packages, setup from setuptools.command.build_ext import build_ext +from setuptools.command.build_py import build_py from setuptools.command.editable_wheel import editable_wheel +from setuptools.command.test import test as test_command from wheel.bdist_wheel import bdist_wheel # from setuptools.command.install import install as install_command @@ -43,9 +43,10 @@ def requirements(filename="requirements.txt"): def build_stan_model(target_dir): print("Importing cmdstanpy...") - import cmdstanpy from multiprocessing import cpu_count + import cmdstanpy + target_cmdstan_dir = (Path(target_dir) / f"cmdstan-{CMDSTAN_VERSION}").resolve() print("target_cmdstan_dir: {}".format(target_cmdstan_dir)) diff --git a/tests/conftest.py b/tests/conftest.py index 06873b31..14ef2307 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,12 @@ -import pytest -import pandas as pd -import numpy as np -import importlib_resources from copy import deepcopy -from orbit.utils.simulation import make_trend, make_seasonality, make_regression +import importlib_resources +import numpy as np +import pandas as pd +import pytest + +from orbit.utils.simulation import (make_regression, make_seasonality, + make_trend) @pytest.fixture diff --git a/tests/orbit/diagnostics/test_backtest.py b/tests/orbit/diagnostics/test_backtest.py index bfbcf469..e8368c36 100644 --- a/tests/orbit/diagnostics/test_backtest.py +++ b/tests/orbit/diagnostics/test_backtest.py @@ -1,9 +1,9 @@ -import pytest -import pandas as pd import numpy as np +import pandas as pd +import pytest -from orbit.diagnostics.backtest import TimeSeriesSplitter, BackTester -from orbit.diagnostics.metrics import smape, wmape, mae +from orbit.diagnostics.backtest import BackTester, TimeSeriesSplitter +from orbit.diagnostics.metrics import mae, smape, wmape from orbit.models import LGT, KTRLite diff --git a/tests/orbit/diagnostics/test_eda_plot.py b/tests/orbit/diagnostics/test_eda_plot.py index fde32af0..80ac98fe 100644 --- a/tests/orbit/diagnostics/test_eda_plot.py +++ b/tests/orbit/diagnostics/test_eda_plot.py @@ -1,5 +1,5 @@ -import pytest import numpy as np +import pytest from orbit.eda import eda_plot diff --git a/tests/orbit/diagnostics/test_plot.py b/tests/orbit/diagnostics/test_plot.py index 4be397c4..ce14683b 100644 --- a/tests/orbit/diagnostics/test_plot.py +++ b/tests/orbit/diagnostics/test_plot.py @@ -1,16 +1,13 @@ -import pytest -import pandas as pd import numpy as np +import pandas as pd +import pytest from orbit.diagnostics.backtest import BackTester from orbit.diagnostics.metrics import smape -from orbit.models import LGT, DLT -from orbit.diagnostics.plot import ( - plot_predicted_data, - plot_predicted_components, - plot_bt_predictions, - plot_bt_predictions2, -) +from orbit.diagnostics.plot import (plot_bt_predictions, plot_bt_predictions2, + plot_predicted_components, + plot_predicted_data) +from orbit.models import DLT, LGT @pytest.mark.parametrize( diff --git a/tests/orbit/diagnostics/test_wbic.py b/tests/orbit/diagnostics/test_wbic.py index 1c9205b2..3394f0c4 100644 --- a/tests/orbit/diagnostics/test_wbic.py +++ b/tests/orbit/diagnostics/test_wbic.py @@ -1,7 +1,7 @@ -import pytest import numpy as np +import pytest -from orbit.models import LGT, DLT, KTR, KTRLite +from orbit.models import DLT, KTR, LGT, KTRLite @pytest.mark.parametrize("estimator", ["stan-mcmc", "stan-map"]) diff --git a/tests/orbit/estimators/test_stan_estimator.py b/tests/orbit/estimators/test_stan_estimator.py index b09c20f6..8d9e98bd 100644 --- a/tests/orbit/estimators/test_stan_estimator.py +++ b/tests/orbit/estimators/test_stan_estimator.py @@ -1,4 +1,4 @@ -from orbit.estimators.stan_estimator import StanEstimatorMCMC, StanEstimatorMAP +from orbit.estimators.stan_estimator import StanEstimatorMAP, StanEstimatorMCMC def test_stan_estimator_mcmc(stan_estimator_lgt_model_input): diff --git a/tests/orbit/models/test_dlt.py b/tests/orbit/models/test_dlt.py index 8f8ae4f0..b3f956d3 100644 --- a/tests/orbit/models/test_dlt.py +++ b/tests/orbit/models/test_dlt.py @@ -1,10 +1,11 @@ from copy import copy -import pytest + import numpy as np +import pytest -from orbit.models import DLT from orbit.constants.constants import PredictionKeys from orbit.exceptions import ModelException, PredictionException +from orbit.models import DLT @pytest.mark.parametrize("estimator", ["stan-map", "stan-mcmc"]) diff --git a/tests/orbit/models/test_ets.py b/tests/orbit/models/test_ets.py index 68e7191a..8fd2f53c 100644 --- a/tests/orbit/models/test_ets.py +++ b/tests/orbit/models/test_ets.py @@ -1,9 +1,10 @@ -import pytest -import numpy as np from copy import copy -from orbit.models import ETS +import numpy as np +import pytest + from orbit.constants.constants import PredictionKeys +from orbit.models import ETS @pytest.mark.parametrize("estimator", ["stan-map", "stan-mcmc"]) diff --git a/tests/orbit/models/test_ktr.py b/tests/orbit/models/test_ktr.py index 97b3d4e4..5272211c 100644 --- a/tests/orbit/models/test_ktr.py +++ b/tests/orbit/models/test_ktr.py @@ -1,9 +1,9 @@ -import pytest import numpy as np import pandas as pd +import pytest -from orbit.models import KTR from orbit.diagnostics.metrics import smape +from orbit.models import KTR SMAPE_TOLERANCE = 0.2 diff --git a/tests/orbit/models/test_ktrlite.py b/tests/orbit/models/test_ktrlite.py index 3d60223e..3b033ca8 100644 --- a/tests/orbit/models/test_ktrlite.py +++ b/tests/orbit/models/test_ktrlite.py @@ -1,9 +1,9 @@ -import pytest import numpy as np import pandas as pd +import pytest -from orbit.models import KTRLite from orbit.diagnostics.metrics import smape +from orbit.models import KTRLite # used for in-sample training insanity check SMAPE_TOLERANCE = 0.28 diff --git a/tests/orbit/models/test_lgt.py b/tests/orbit/models/test_lgt.py index f7fbc0f1..5d6779cc 100644 --- a/tests/orbit/models/test_lgt.py +++ b/tests/orbit/models/test_lgt.py @@ -1,9 +1,10 @@ from copy import copy -import pytest + import numpy as np +import pytest -from orbit.models import LGT from orbit.constants.constants import PredictionKeys +from orbit.models import LGT @pytest.mark.parametrize("estimator", ["stan-map", "stan-mcmc"]) diff --git a/tests/orbit/utils/test_knots.py b/tests/orbit/utils/test_knots.py index fbeedfed..9949766f 100644 --- a/tests/orbit/utils/test_knots.py +++ b/tests/orbit/utils/test_knots.py @@ -1,7 +1,8 @@ -import pytest import numpy as np import pandas as pd -from orbit.utils.knots import get_knot_idx, get_knot_dates +import pytest + +from orbit.utils.knots import get_knot_dates, get_knot_idx @pytest.mark.parametrize("num_of_segments", [0, 1, 3, 10])