def test_fh_in_fit_opt(Forecaster): f = _construct_instance(Forecaster) f.fit(y_train, fh=FH0) np.testing.assert_array_equal(f.fh, FH0) f.predict() np.testing.assert_array_equal(f.fh, FH0)
def _construct_fit(Estimator, **kwargs): estimator = _construct_instance(Estimator) args = _make_args(estimator, "fit", **kwargs)[:2] return estimator.fit(*args)
def test_no_fh_opt(Forecaster): f = _construct_instance(Forecaster) f.fit(y_train) # not passing fh to either fit or predict raises error with pytest.raises(ValueError): f.predict()
def test_y_invalid_type_raises_error(Forecaster, y): """Test that invalid y input types raise error.""" f = _construct_instance(Forecaster) with pytest.raises(TypeError, match=r"type"): f.fit(y, fh=FH0)
def check_transform_inverse_transform_equivalent(Estimator): estimator = _construct_instance(Estimator) X = _make_args(estimator, "fit")[0] Xt = estimator.fit_transform(X) Xit = estimator.inverse_transform(Xt) _assert_array_almost_equal(X, Xit)
def test_y_multivariate_raises_error(Forecaster): # Check that multivariate y raises an appropriate error message. y = _make_series(n_columns=2) f = _construct_instance(Forecaster) with pytest.raises(ValueError, match=r"univariate"): f.fit(y, fh=FH0)
def test_update_predict_single(Forecaster, fh, update_params): # Check correct time index of update-predict f = _construct_instance(Forecaster) f.fit(y_train, fh=fh) y_pred = f.update_predict_single(y_test, update_params=update_params) _assert_correct_pred_time_index(y_pred.index, y_test.index[-1], fh)
def test_y_invalid_type_raises_error(Forecaster, y): f = _construct_instance(Forecaster) with pytest.raises(TypeError, match=r"type"): f.fit(y, fh=FH0)
def test_no_fh_in_fit_req(Forecaster): f = _construct_instance(Forecaster) # fh required in fit, raises error if not passed with pytest.raises(ValueError): f.fit(y_train)
def test_same_fh_in_fit_and_predict_opt(Forecaster): f = _construct_instance(Forecaster) # passing the same fh to both fit and predict works f.fit(y_train, fh=FH0) f.predict(FH0) np.testing.assert_array_equal(f.fh, FH0)