Implement lazy import for xreg dependencies in forecast_with_covariates to avoid unnecessary JAX installation
This commit is contained in:
@@ -17,17 +17,20 @@ import collections
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from typing import Any, Literal, Sequence
|
from typing import Any, Literal, Sequence, TYPE_CHECKING
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from utilsforecast.processing import make_future_dataframe
|
from utilsforecast.processing import make_future_dataframe
|
||||||
|
|
||||||
from . import xreg_lib
|
if TYPE_CHECKING:
|
||||||
|
from . import xreg_lib
|
||||||
Category = xreg_lib.Category
|
Category = xreg_lib.Category
|
||||||
XRegMode = xreg_lib.XRegMode
|
XRegMode = xreg_lib.XRegMode
|
||||||
|
else:
|
||||||
|
Category = int | str
|
||||||
|
XRegMode = str
|
||||||
|
|
||||||
_TOL = 1e-6
|
_TOL = 1e-6
|
||||||
DEFAULT_QUANTILES = (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)
|
DEFAULT_QUANTILES = (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)
|
||||||
@@ -42,8 +45,7 @@ def moving_average(arr, window_size):
|
|||||||
"""Calculates the moving average using NumPy's convolution function."""
|
"""Calculates the moving average using NumPy's convolution function."""
|
||||||
# Pad with zeros to handle initial window positions
|
# Pad with zeros to handle initial window positions
|
||||||
arr_padded = np.pad(arr, (window_size - 1, 0), "constant")
|
arr_padded = np.pad(arr, (window_size - 1, 0), "constant")
|
||||||
smoothed_arr = (np.convolve(arr_padded, np.ones(window_size), "valid") /
|
smoothed_arr = (np.convolve(arr_padded, np.ones(window_size), "valid") / window_size)
|
||||||
window_size)
|
|
||||||
return [smoothed_arr, arr - smoothed_arr]
|
return [smoothed_arr, arr - smoothed_arr]
|
||||||
|
|
||||||
|
|
||||||
@@ -464,6 +466,8 @@ class TimesFmBase:
|
|||||||
the outputs of the xreg.
|
the outputs of the xreg.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from . import xreg_lib
|
||||||
|
|
||||||
# Verify and bookkeep covariates.
|
# Verify and bookkeep covariates.
|
||||||
if not (dynamic_numerical_covariates or dynamic_categorical_covariates or
|
if not (dynamic_numerical_covariates or dynamic_categorical_covariates or
|
||||||
static_numerical_covariates or static_categorical_covariates):
|
static_numerical_covariates or static_categorical_covariates):
|
||||||
|
|||||||
Reference in New Issue
Block a user