Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if stationary:
d = D = 0
# now for seasonality
if m == 1:
D = max_P = max_Q = 0
# m must be > 1 for nsdiffs
elif D is None: # we don't have a D yet and we need one (seasonal)
seasonal_test_args = seasonal_test_args \
if seasonal_test_args is not None else dict()
D = nsdiffs(xx, m=m, test=seasonal_test, max_D=max_D,
**seasonal_test_args)
if D > 0 and exogenous is not None:
diffxreg = diff(exogenous, differences=D, lag=m)
# check for constance on any column
if np.apply_along_axis(is_constant, arr=diffxreg, axis=0).any():
D -= 1
# D might still be None if not seasonal. Py 3 will throw and error for that
# unless we explicitly check for ``seasonal``
if D > 0:
dx = diff(xx, differences=D, lag=m)
else:
dx = xx
# If D was too big, we might have gotten rid of x altogether!
if dx.shape[0] == 0:
raise ValueError("The seasonal differencing order, D=%i, was too "
"large for your time series, and after differencing, "
"there are no samples remaining in your data. "
dx = xx
# If D was too big, we might have gotten rid of x altogether!
if dx.shape[0] == 0:
raise ValueError("The seasonal differencing order, D=%i, was too "
"large for your time series, and after differencing, "
"there are no samples remaining in your data. "
"Try a smaller value for D, or if you didn't set D "
"to begin with, try setting it explicitly. This can "
"also occur in seasonal settings when m is too large."
% D)
# difference the exogenous matrix
if exogenous is not None:
if D > 0:
diffxreg = diff(exogenous, differences=D, lag=m)
else:
diffxreg = exogenous
else:
# here's the thing... we're only going to use diffxreg if exogenous
# was not None in the first place. However, PyCharm doesn't know that
# and it thinks we might use it before assigning it. Therefore, assign
# it to None as a default value and it won't raise the warning anymore.
diffxreg = None
# determine/set the order of differencing by estimating the number of
# orders it would take in order to make the TS stationary.
if d is None:
offset_test_args = offset_test_args \
if offset_test_args is not None else dict()
d = ndiffs(dx, test=test, alpha=alpha, max_d=max_d, **offset_test_args)
d -= 1
# check differences (do we want to warn?...)
if error_action == 'warn' and not suppress_warnings:
if D >= 2:
warnings.warn("Having more than one seasonal differences is "
"not recommended. Please consider using only one "
"seasonal difference.")
# if D is -1, this will be off, so we include the OR
elif D + d > 2 or d > 2:
warnings.warn("Having 3 or more differencing operations is not "
"recommended. Please consider reducing the total "
"number of differences.")
if d > 0:
dx = diff(dx, differences=d, lag=1)
# check for constance
if is_constant(dx):
if exogenous is None and not (D > 0 or d < 2):
raise ValueError('data follow a simple polynomial and are not '
'suitable for ARIMA modeling')
# perfect regression
ssn = None if not seasonal else (0, D, 0, m)
return _return_wrapper(
_post_ppc_arima(_fit_arima(y, xreg=exogenous, order=(0, d, 0),
seasonal_order=ssn,
start_params=start_params, trend=trend,
method=method, transparams=transparams,
solver=solver, maxiter=maxiter,
disp=disp, callback=callback,
d -= 1
# check differences (do we want to warn?...)
if error_action == 'warn' and not suppress_warnings:
if D >= 2:
warnings.warn("Having more than one seasonal differences is "
"not recommended. Please consider using only one "
"seasonal difference.", ModelFitWarning)
# if D is -1, this will be off, so we include the OR
elif D + d > 2 or d > 2:
warnings.warn("Having 3 or more differencing operations is not "
"recommended. Please consider reducing the total "
"number of differences.", ModelFitWarning)
if d > 0:
dx = diff(dx, differences=d, lag=1)
# check for constance
if is_constant(dx):
if exogenous is None and not (D > 0 or d < 2):
raise ValueError('data follow a simple polynomial and are not '
'suitable for ARIMA modeling')
# perfect regression
ssn = (0, 0, 0, 0) if not seasonal else (0, D, 0, m)
return _return_wrapper(
_post_ppc_arima(
solvers._fit_arima(
y, xreg=exogenous, order=(0, d, 0),
seasonal_order=ssn,
start_params=start_params, trend=trend,
method=method, maxiter=maxiter,
elif D is None: # we don't have a D yet and we need one (seasonal)
seasonal_test_args = seasonal_test_args \
if seasonal_test_args is not None else dict()
D = nsdiffs(xx, m=m, test=seasonal_test, max_D=max_D,
**seasonal_test_args)
if D > 0 and exogenous is not None:
diffxreg = diff(exogenous, differences=D, lag=m)
# check for constance on any column
if np.apply_along_axis(is_constant, arr=diffxreg, axis=0).any():
D -= 1
# D might still be None if not seasonal. Py 3 will throw and error for that
# unless we explicitly check for ``seasonal``
if D > 0:
dx = diff(xx, differences=D, lag=m)
else:
dx = xx
# If D was too big, we might have gotten rid of x altogether!
if dx.shape[0] == 0:
raise ValueError("The seasonal differencing order, D=%i, was too "
"large for your time series, and after differencing, "
"there are no samples remaining in your data. "
"Try a smaller value for D, or if you didn't set D "
"to begin with, try setting it explicitly. This can "
"also occur in seasonal settings when m is too large."
% D)
# difference the exogenous matrix
if exogenous is not None:
if D > 0:
dx = xx
# If D was too big, we might have gotten rid of x altogether!
if dx.shape[0] == 0:
raise ValueError("The seasonal differencing order, D=%i, was too "
"large for your time series, and after differencing, "
"there are no samples remaining in your data. "
"Try a smaller value for D, or if you didn't set D "
"to begin with, try setting it explicitly. This can "
"also occur in seasonal settings when m is too large."
% D)
# difference the exogenous matrix
if exogenous is not None:
if D > 0:
diffxreg = diff(exogenous, differences=D, lag=m)
else:
diffxreg = exogenous
else:
# here's the thing... we're only going to use diffxreg if exogenous
# was not None in the first place. However, PyCharm doesn't know that
# and it thinks we might use it before assigning it. Therefore, assign
# it to None as a default value and it won't raise the warning anymore.
diffxreg = None
# determine/set the order of differencing by estimating the number of
# orders it would take in order to make the TS stationary.
if d is None:
offset_test_args = offset_test_args \
if offset_test_args is not None else dict()
d = ndiffs(dx, test=test, alpha=alpha, max_d=max_d, **offset_test_args)
elif D is None: # we don't have a D yet and we need one (seasonal)
seasonal_test_args = seasonal_test_args \
if seasonal_test_args is not None else dict()
D = nsdiffs(xx, m=m, test=seasonal_test, max_D=max_D,
**seasonal_test_args)
if D > 0 and exogenous is not None:
diffxreg = diff(exogenous, differences=D, lag=m)
# check for constance on any column
if np.apply_along_axis(is_constant, arr=diffxreg, axis=0).any():
D -= 1
# D might still be None if not seasonal. Py 3 will throw and error for that
# unless we explicitly check for ``seasonal``
if D > 0:
dx = diff(xx, differences=D, lag=m)
else:
dx = xx
# If D was too big, we might have gotten rid of x altogether!
if dx.shape[0] == 0:
raise ValueError("The seasonal differencing order, D=%i, was too "
"large for your time series, and after differencing, "
"there are no samples remaining in your data. "
"Try a smaller value for D, or if you didn't set D "
"to begin with, try setting it explicitly. This can "
"also occur in seasonal settings when m is too large."
% D)
# difference the exogenous matrix
if exogenous is not None:
if D > 0:
else:
# here's the thing... we're only going to use diffxreg if exogenous
# was not None in the first place. However, PyCharm doesn't know that
# and it thinks we might use it before assigning it. Therefore, assign
# it to None as a default value and it won't raise the warning anymore.
diffxreg = None
# determine/set the order of differencing by estimating the number of
# orders it would take in order to make the TS stationary.
if d is None:
offset_test_args = offset_test_args \
if offset_test_args is not None else dict()
d = ndiffs(dx, test=test, alpha=alpha, max_d=max_d, **offset_test_args)
if d > 0 and exogenous is not None:
diffxreg = diff(diffxreg, differences=d, lag=1)
# if any columns are constant, subtract one order of differencing
if np.apply_along_axis(is_constant, arr=diffxreg, axis=0).any():
d -= 1
# check differences (do we want to warn?...)
if error_action == 'warn' and not suppress_warnings:
if D >= 2:
warnings.warn("Having more than one seasonal differences is "
"not recommended. Please consider using only one "
"seasonal difference.")
# if D is -1, this will be off, so we include the OR
elif D + d > 2 or d > 2:
warnings.warn("Having 3 or more differencing operations is not "
"recommended. Please consider reducing the total "
"number of differences.")