code: def arima2(x, model, xreg, method):
      m = model["arma"][4]  # 5
      use_drift = "drift" in model["coef"].keys()
      use_intercept = "intercept" in model["coef"].keys()
      use_xreg = model["xreg"] is not None
      sigma2 = model["sigma2"]
      if use_drift:
          n = len(model["x"])
          time = np.arange(0, (n + 1) / m, 1 / m)[:n].reshape(-1, 1)
          # drift is the first column of the exogenous regressors
          driftmod = sm.OLS(
              model["xreg"][:, 0], sm.add_constant(time)
          ).fit()
          n = len(x)
          newtime = np.arange(0, (n + 1) / m, 1 / m)[:n].reshape(-1, 1)
          newxreg = driftmod.predict(sm.add_constant(newtime)).reshape(
              -1, 1
          )
          if xreg is not None:
              xreg = np.concatenate([newxreg, xreg], axis=1)
          else:
              xreg = newxreg
          use_xreg = True
      if model["xreg"] is not None:
          if xreg is None:
              raise Exception("No regressors provided")
          if xreg.shape[1] != model["xreg"].shape[1]:
              raise Exception(
                  "Number of regressors does not match fitted model"
              )
  
      seas_arma = [model["arma"][i] for i in [2, 3, 6]]  # 3, 4, 7
      order = tuple(model["arma"][i] for i in [0, 5, 1])  # 1, 6, 2
      coefs = np.array(list(model["coef"].values()))
      if model["arma"][4] > 1 and np.sum(
          np.abs(seas_arma) > 0
      ):  # seasonal model
          seasonal = dict(
              order=tuple(model["arma"][i] for i in [2, 6, 3]),
              period=m,  # 3, 7, 4
          )
          refit = Arima(
              x=x,
              order=order,
              seasonal=seasonal,
              include_mean=use_intercept,
              method=method,
              fixed=coefs,
              xreg=xreg if use_xreg else None,
          )
      elif (
          len(model["coef"]) > 0
      ):  # Nonseasonal model with some parameters
          refit = Arima(
              x=x,
              order=order,
              include_mean=use_intercept,
              method=method,
              fixed=coefs,
              xreg=xreg if use_xreg else None,
          )
      else:  # no parameters
          refit = Arima(
              x=x,
              order=order,
              include_mean=False,
              method=method,
          )
      n_coef = len(refit["coef"])
      refit["var_coef"] = np.zeros((n_coef, n_coef), dtype=np.float32)
      if use_xreg:
          refit["xreg"] = xreg
      refit["sigma2"] = sigma2
      if use_drift:
          refit["coef"] = change_drift_name(refit["coef"])
      return refit
  
imports: import math
  import warnings
  from collections import namedtuple
  from functools import partial
  from typing import Optional, Dict, Union, Tuple
  import numpy
  import pandas
  import statsmodels.api
  from numba import njit
  from scipy.optimize import minimize
  from scipy.stats import norm
  from .mstl import mstl
  from .utils import CACHE, NOGIL
label_desc: Use image node_id 26 for calling a global function with example usage: arima2(x, model, xreg, method) and returns: refit