def test_fit_predict_ts_with_datetime_in_X_column(ts_data_seasonal):
    X, y = ts_data_seasonal
    assert isinstance(X.index, pd.DatetimeIndex)
    assert isinstance(y.index, pd.DatetimeIndex)

    m_clf = ARIMARegressor(d=None)
    m_clf.fit(X=X[:250], y=y[:250])
    y_pred = m_clf.predict(X=X[250:])

    X['Sample'] = pd.date_range(start='1/1/2016', periods=500)

    dt_clf = ARIMARegressor(d=None)
    dt_clf.fit(X=X[:250], y=y[:250])
    y_pred_dt = dt_clf.predict(X=X[250:])

    assert isinstance(y_pred_dt, woodwork.DataColumn)
    pd.testing.assert_series_equal(y_pred.to_series(), y_pred_dt.to_series())
def test_fit_predict_ts_no_X_out_of_sample(ts_data_seasonal):
    X, y = ts_data_seasonal

    fh_ = forecasting.ForecastingHorizon(y[250:].index, is_relative=False)

    a_clf = sktime_arima.AutoARIMA()
    a_clf.fit(y=y[:250])
    y_pred_sk = a_clf.predict(fh=fh_)

    m_clf = ARIMARegressor(d=None)
    m_clf.fit(X=None, y=y[:250])
    y_pred = m_clf.predict(X=None, y=y[250:])

    assert (y_pred_sk.to_period('D') == y_pred.to_series()).all()
def test_fit_predict_date_index_named_out_of_sample(X_none, ts_data_seasonal):
    X, y = ts_data_seasonal

    fh_ = forecasting.ForecastingHorizon(y[250:].index, is_relative=False)

    a_clf = sktime_arima.AutoARIMA()
    if X_none:
        clf = a_clf.fit(y=y[:250])
        y_pred_sk = clf.predict(fh=fh_)
    else:
        clf = a_clf.fit(X=X[:250], y=y[:250])
        y_pred_sk = clf.predict(fh=fh_, X=X[250:])

    X = X.reset_index()
    assert not isinstance(X.index, pd.DatetimeIndex)
    m_clf = ARIMARegressor(date_index='index', d=None)
    if X_none:
        m_clf.fit(X=None, y=y[:250])
        y_pred = m_clf.predict(X=None, y=y[250:])
    else:
        m_clf.fit(X=X[:250], y=y[:250])
        y_pred = m_clf.predict(X=X[250:], y=y[250:])

    assert (y_pred_sk.to_period('D') == y_pred.to_series()).all()
def test_fit_predict_ts_with_X_and_y_index_out_of_sample(ts_data_seasonal):
    X, y = ts_data_seasonal
    assert isinstance(X.index, pd.DatetimeIndex)
    assert isinstance(y.index, pd.DatetimeIndex)

    fh_ = forecasting.ForecastingHorizon(y[250:].index, is_relative=False)

    a_clf = sktime_arima.AutoARIMA()
    clf = a_clf.fit(X=X[:250], y=y[:250])
    y_pred_sk = clf.predict(fh=fh_, X=X[250:])

    m_clf = ARIMARegressor(d=None)
    m_clf.fit(X=X[:250], y=y[:250])
    y_pred = m_clf.predict(X=X[250:])

    assert (y_pred_sk.to_period('D') == y_pred.to_series()).all()
def test_fit_predict_ts_with_only_datetime_column_in_X(ts_data_seasonal):
    X, y = ts_data_seasonal
    assert isinstance(X.index, pd.DatetimeIndex)
    assert isinstance(y.index, pd.DatetimeIndex)

    fh_ = forecasting.ForecastingHorizon(y[250:].index, is_relative=False)

    a_clf = sktime_arima.AutoARIMA()
    clf = a_clf.fit(y=y[:250])
    y_pred_sk = clf.predict(fh=fh_)

    X = X.drop(["features"], axis=1)

    m_clf = ARIMARegressor(d=None)
    m_clf.fit(X=X[:250], y=y[:250])
    y_pred = m_clf.predict(X=X[250:])

    assert (y_pred_sk.to_period('D') == y_pred.to_series()).all()
def test_fit_predict_ts_with_X_and_y_index(mock_get_dates, mock_format_dates,
                                           ts_data_seasonal):
    X, y = ts_data_seasonal
    assert isinstance(X.index, pd.DatetimeIndex)
    assert isinstance(y.index, pd.DatetimeIndex)

    mock_get_dates.return_value = (X.index, X)
    mock_format_dates.return_value = (X, y, None)

    fh_ = forecasting.ForecastingHorizon(y.index, is_relative=False)

    a_clf = sktime_arima.AutoARIMA()
    clf = a_clf.fit(X=X, y=y)
    y_pred_sk = clf.predict(fh=fh_, X=X)

    m_clf = ARIMARegressor(d=None)
    m_clf.fit(X=X, y=y)
    mock_format_dates.return_value = (X, y, fh_)
    y_pred = m_clf.predict(X=X)

    assert (y_pred_sk == y_pred.to_series()).all()