# Buggy code
def _fit_start_params_hr(self, order, start_ar_lags=None):
    """
    Get starting parameters for fit.

    Parameters
    ----------
    order : iterable
        (p,q,k) - AR lags, MA lags, and number of exogenous variables
        including the constant.
    start_ar_lags : int, optional
        If start_ar_lags is not None, rather than fitting an AR process
        according to best BIC, fits an AR process with a lag length equal
        to start_ar_lags.

    Returns
    -------
    start_params : array
        A first guess at the starting parameters.

    Notes
    -----
    If necessary, fits an AR process with the laglength start_ar_lags, or
    selected according to best BIC if start_ar_lags is None.  Obtain the
    residuals.  Then fit an ARMA(p,q) model via OLS using these residuals
    for a first approximation.  Uses a separate OLS regression to find the
    coefficients of exogenous variables.

    References
    ----------
    Hannan, E.J. and Rissanen, J.  1982.  "Recursive estimation of mixed
        autoregressive-moving average order."  `Biometrika`.  69.1.

    Durbin, J. 1960. "The Fitting of Time-Series Models."
    `Review of the International Statistical Institute`. Vol. 28, No. 3
    """
    p, q, k = order
    start_params = zeros((p + q + k))
    endog = self.endog.copy()  # copy because overwritten
    exog = self.exog
    if k != 0:
        ols_params = GLS(endog, exog).fit().params
        start_params[:k] = ols_params
        endog -= np.dot(exog, ols_params).squeeze()
    if q != 0:
        if p != 0:
            # make sure we don't run into small data problems in AR fit
            nobs = len(endog)
            if start_ar_lags is None:
                maxlag = int(round(12 * (nobs / 100.0) ** (1 / 4.0)))
                if maxlag >= nobs:
                    maxlag = nobs - 1
                armod = AR(endog).fit(ic="bic", trend="nc", maxlag=maxlag)
            else:
                if start_ar_lags >= nobs:
                    start_ar_lags = nobs - 1
                armod = AR(endog).fit(trend="nc", maxlag=start_ar_lags)
            arcoefs_tmp = armod.params
            p_tmp = armod.k_ar
            # it's possible in small samples that optimal lag-order
            # doesn't leave enough obs. No consistent way to fix.
            if p_tmp + q >= len(endog):
                raise ValueError(
                    "Proper starting parameters cannot"
                    " be found for this order with this "
                    "number of observations. Use the "
                    "start_params argument, or set "
                    "start_ar_lags to an integer less than "
                    "len(endog) - q."
                )
            resid = endog[p_tmp:] - np.dot(
                lagmat(endog, p_tmp, trim="both"), arcoefs_tmp
            )
            if p < p_tmp + q:
                endog_start = p_tmp + q - p
                resid_start = 0
            else:
                endog_start = 0
                resid_start = p - p_tmp - q
            lag_endog = lagmat(endog, p, "both")[endog_start:]
            lag_resid = lagmat(resid, q, "both")[resid_start:]
            # stack ar lags and resids
            X = np.column_stack((lag_endog, lag_resid))
            coefs = GLS(endog[max(p_tmp + q, p) :], X).fit().params
            start_params[k : k + p + q] = coefs
        else:
            start_params[k + p : k + p + q] = yule_walker(endog, order=q)[0]
    if q == 0 and p != 0:
        arcoefs = yule_walker(endog, order=p)[0]
        start_params[k : k + p] = arcoefs

    # check AR coefficients
    if p and not np.all(np.abs(np.roots(np.r_[1, -start_params[k : k + p]])) < 1):
        raise ValueError(
            "The computed initial AR coefficients are not "
            "stationary\nYou should induce stationarity, "
            "choose a different model order, or you can\n"
            "pass your own start_params."
        )
    # check MA coefficients
    elif q and not np.all(np.abs(np.roots(np.r_[1, start_params[k + p :]])) < 1):
        raise ValueError(
            "The computed initial MA coefficients are not "
            "invertible\nYou should induce invertibility, "
            "choose a different model order, or you can\n"
            "pass your own start_params."
        )

    # check MA coefficients
    return start_params


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-964a74d33f5a> in <module>()
5
6 model = sm.tsa.arima_model.ARIMA(ts, order=(0, 2, 0))
----> 7 fitted = model.fit(disp=-1)
8
9

/usr/local/lib/python3.5/dist-packages/statsmodels/tsa/arima_model.py in fit(self, start_params, trend, method, transparams, solver, maxiter, full_output, disp, callback, start_ar_lags, **kwargs)
1149                                            method, transparams, solver,
1150                                            maxiter, full_output, disp,
-> 1151                                            callback, start_ar_lags, **kwargs)
1152         normalized_cov_params = None  # TODO: fix this?
1153         arima_fit = ARIMAResults(self, mlefit._results.params,

/usr/local/lib/python3.5/dist-packages/statsmodels/tsa/arima_model.py in fit(self, start_params, trend, method, transparams, solver, maxiter, full_output, disp, callback, start_ar_lags, **kwargs)
954         else:  # estimate starting parameters
955             start_params = self._fit_start_params((k_ar, k_ma, k), method,
--> 956                                                   start_ar_lags)
957
958         if transparams:  # transform initial parameters to ensure invertibility

/usr/local/lib/python3.5/dist-packages/statsmodels/tsa/arima_model.py in _fit_start_params(self, order, method, start_ar_lags)
572     def _fit_start_params(self, order, method, start_ar_lags=None):
573         if method != 'css-mle':  # use Hannan-Rissanen to get start params
--> 574             start_params = self._fit_start_params_hr(order, start_ar_lags)
575         else:  # use CSS to get start params
576             func = lambda params: -self.loglike_css(params)

/usr/local/lib/python3.5/dist-packages/statsmodels/tsa/arima_model.py in _fit_start_params_hr(self, order, start_ar_lags)
506             ols_params = GLS(endog, exog).fit().params
507             start_params[:k] = ols_params
--> 508             endog -= np.dot(exog, ols_params).squeeze()
509         if q != 0:
510             if p != 0:

TypeError: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

# Fixed code
def _fit_start_params_hr(self, order, start_ar_lags=None):
    """
    Get starting parameters for fit.

    Parameters
    ----------
    order : iterable
        (p,q,k) - AR lags, MA lags, and number of exogenous variables
        including the constant.
    start_ar_lags : int, optional
        If start_ar_lags is not None, rather than fitting an AR process
        according to best BIC, fits an AR process with a lag length equal
        to start_ar_lags.

    Returns
    -------
    start_params : array
        A first guess at the starting parameters.

    Notes
    -----
    If necessary, fits an AR process with the laglength start_ar_lags, or
    selected according to best BIC if start_ar_lags is None.  Obtain the
    residuals.  Then fit an ARMA(p,q) model via OLS using these residuals
    for a first approximation.  Uses a separate OLS regression to find the
    coefficients of exogenous variables.

    References
    ----------
    Hannan, E.J. and Rissanen, J.  1982.  "Recursive estimation of mixed
        autoregressive-moving average order."  `Biometrika`.  69.1.

    Durbin, J. 1960. "The Fitting of Time-Series Models."
    `Review of the International Statistical Institute`. Vol. 28, No. 3
    """
    p, q, k = order
    start_params = zeros((p + q + k))
    # make copy of endog because overwritten
    endog = np.array(self.endog, np.float64)
    exog = self.exog
    if k != 0:
        ols_params = OLS(endog, exog).fit().params
        start_params[:k] = ols_params
        endog -= np.dot(exog, ols_params).squeeze()
    if q != 0:
        if p != 0:
            # make sure we don't run into small data problems in AR fit
            nobs = len(endog)
            if start_ar_lags is None:
                maxlag = int(round(12 * (nobs / 100.0) ** (1 / 4.0)))
                if maxlag >= nobs:
                    maxlag = nobs - 1
                armod = AR(endog).fit(ic="bic", trend="nc", maxlag=maxlag)
            else:
                if start_ar_lags >= nobs:
                    start_ar_lags = nobs - 1
                armod = AR(endog).fit(trend="nc", maxlag=start_ar_lags)
            arcoefs_tmp = armod.params
            p_tmp = armod.k_ar
            # it's possible in small samples that optimal lag-order
            # doesn't leave enough obs. No consistent way to fix.
            if p_tmp + q >= len(endog):
                raise ValueError(
                    "Proper starting parameters cannot"
                    " be found for this order with this "
                    "number of observations. Use the "
                    "start_params argument, or set "
                    "start_ar_lags to an integer less than "
                    "len(endog) - q."
                )
            resid = endog[p_tmp:] - np.dot(
                lagmat(endog, p_tmp, trim="both"), arcoefs_tmp
            )
            if p < p_tmp + q:
                endog_start = p_tmp + q - p
                resid_start = 0
            else:
                endog_start = 0
                resid_start = p - p_tmp - q
            lag_endog = lagmat(endog, p, "both")[endog_start:]
            lag_resid = lagmat(resid, q, "both")[resid_start:]
            # stack ar lags and resids
            X = np.column_stack((lag_endog, lag_resid))
            coefs = OLS(endog[max(p_tmp + q, p) :], X).fit().params
            start_params[k : k + p + q] = coefs
        else:
            start_params[k + p : k + p + q] = yule_walker(endog, order=q)[0]
    if q == 0 and p != 0:
        arcoefs = yule_walker(endog, order=p)[0]
        start_params[k : k + p] = arcoefs

    # check AR coefficients
    if p and not np.all(np.abs(np.roots(np.r_[1, -start_params[k : k + p]])) < 1):
        raise ValueError(
            "The computed initial AR coefficients are not "
            "stationary\nYou should induce stationarity, "
            "choose a different model order, or you can\n"
            "pass your own start_params."
        )
    # check MA coefficients
    elif q and not np.all(np.abs(np.roots(np.r_[1, start_params[k + p :]])) < 1):
        raise ValueError(
            "The computed initial MA coefficients are not "
            "invertible\nYou should induce invertibility, "
            "choose a different model order, or you can\n"
            "pass your own start_params."
        )

    # check MA coefficients
    return start_params