Skip to content

Commit

Permalink
update_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierEscobarOrtiz committed Nov 15, 2023
1 parent 6dd8251 commit e78579e
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 13 deletions.
4 changes: 2 additions & 2 deletions skforecast/ForecasterAutoreg/tests/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_predict_NotFittedError_when_fitted_is_False():
forecaster = ForecasterAutoreg(LinearRegression(), lags=3)

err_msg = re.escape(
('This Forecaster instance is not fitted yet. Call `fit` with '
'appropriate arguments before using predict.')
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict(steps=5)
Expand Down
15 changes: 15 additions & 0 deletions skforecast/ForecasterAutoreg/tests/test_predict_bootstrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import numpy as np
import pandas as pd
from sklearn.exceptions import NotFittedError
from skforecast.ForecasterAutoreg import ForecasterAutoreg
from skforecast.preprocessing import TimeSeriesDifferentiator
from sklearn.linear_model import LinearRegression
Expand All @@ -16,6 +17,20 @@
from .fixtures_ForecasterAutoreg import data # to test results when using differentiation


def test_predict_bootstrapping_NotFittedError_when_fitted_is_False():
"""
Test NotFittedError is raised when fitted is False.
"""
forecaster = ForecasterAutoreg(LinearRegression(), lags=3)

err_msg = re.escape(
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict_bootstrapping(steps=1)


def test_predict_bootstrapping_ValueError_when_out_sample_residuals_is_None():
"""
Test ValueError is raised when in_sample_residuals=False and
Expand Down
6 changes: 3 additions & 3 deletions skforecast/ForecasterAutoregCustom/tests/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_predictors(y): # pragma: no cover

lags = y[-1:-6:-1]

return lags
return lags


def test_predict_NotFittedError_when_fitted_is_False():
Expand All @@ -46,8 +46,8 @@ def test_predict_NotFittedError_when_fitted_is_False():
)

err_msg = re.escape(
('This Forecaster instance is not fitted yet. Call `fit` with '
'appropriate arguments before using predict.')
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict(steps=5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import numpy as np
import pandas as pd
from sklearn.exceptions import NotFittedError
from skforecast.ForecasterAutoregCustom import ForecasterAutoregCustom
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
Expand All @@ -21,7 +22,25 @@ def create_predictors(y): # pragma: no cover

lags = y[-1:-4:-1]

return lags
return lags


def test_predict_bootstrapping_NotFittedError_when_fitted_is_False():
"""
Test NotFittedError is raised when fitted is False.
"""
forecaster = ForecasterAutoregCustom(
regressor = LinearRegression(),
fun_predictors = create_predictors,
window_size = 5
)

err_msg = re.escape(
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict_bootstrapping(steps=1)


def test_predict_interval_exception_when_out_sample_residuals_is_None():
Expand Down
4 changes: 2 additions & 2 deletions skforecast/ForecasterAutoregMultiSeries/tests/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_predict_NotFittedError_when_fitted_is_False():
forecaster = ForecasterAutoregMultiSeries(LinearRegression(), lags=5)

err_msg = re.escape(
('This Forecaster instance is not fitted yet. Call `fit` with '
'appropriate arguments before using predict.')
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict(steps=5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# ==============================================================================
import re
import pytest
from pytest import approx
import numpy as np
import pandas as pd
from sklearn.exceptions import NotFittedError
from skforecast.ForecasterAutoregMultiSeries import ForecasterAutoregMultiSeries
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler
Expand All @@ -24,6 +24,20 @@
)


def test_predict_bootstrapping_NotFittedError_when_fitted_is_False():
"""
Test NotFittedError is raised when fitted is False.
"""
forecaster = ForecasterAutoregMultiSeries(LinearRegression(), lags=5)

err_msg = re.escape(
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict_bootstrapping(steps=1, levels=None)


def test_predict_bootstrapping_ValueError_when_not_in_sample_residuals_for_any_level():
"""
Test ValueError is raised when in_sample_residuals=True but there is no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def test_predict_NotFittedError_when_fitted_is_False():
)

err_msg = re.escape(
('This Forecaster instance is not fitted yet. Call `fit` with '
'appropriate arguments before using predict.')
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict(steps=5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# ==============================================================================
import re
import pytest
from pytest import approx
import numpy as np
import pandas as pd
from sklearn.exceptions import NotFittedError
from skforecast.ForecasterAutoregMultiSeriesCustom import ForecasterAutoregMultiSeriesCustom
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler
Expand Down Expand Up @@ -32,6 +32,24 @@ def create_predictors(y): # pragma: no cover
return lags


def test_predict_bootstrapping_NotFittedError_when_fitted_is_False():
"""
Test NotFittedError is raised when fitted is False.
"""
forecaster = ForecasterAutoregMultiSeriesCustom(
regressor = LinearRegression(),
fun_predictors = create_predictors,
window_size = 5
)

err_msg = re.escape(
("This Forecaster instance is not fitted yet. Call `fit` with "
"appropriate arguments before using predict.")
)
with pytest.raises(NotFittedError, match = err_msg):
forecaster.predict(steps=5)


def test_predict_bootstrapping_ValueError_when_not_in_sample_residuals_for_any_level():
"""
Test ValueError is raised when in_sample_residuals=True but there is no
Expand Down
2 changes: 1 addition & 1 deletion skforecast/datasets/tests/test_fetch_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_fetch_dataset():
assert df.index[-1].strftime('%Y-%m-%d') == '2008-06-01'

# Test fetching the 'items_sales' dataset
df = fetch_dataset('items_sales', version='latest', raw=False, verbose=False)
df = fetch_dataset('items_sales', version='latest', raw=False, verbose=True)
assert isinstance(df, pd.DataFrame)
assert df.shape == (1097, 3)
assert df.index.freq == 'D'
Expand Down
1 change: 1 addition & 0 deletions skforecast/datasets/tests/test_load_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_load_demo_dataset():
Test load_demo_dataset function.
"""
df = load_demo_dataset()

assert isinstance(df, pd.Series)
assert df.index.freq == 'MS'
assert df.index.is_monotonic_increasing
Expand Down

0 comments on commit e78579e

Please sign in to comment.