diff --git a/tests/test_timeseriesnormalizer.py b/tests/test_timeseriesnormalizer.py new file mode 100644 index 0000000..cd11fa0 --- /dev/null +++ b/tests/test_timeseriesnormalizer.py @@ -0,0 +1,47 @@ +import numpy as np +import pandas as pd +import pytest + +from apyxl import TimeSeriesNormalizer + + +@pytest.fixture +def sample_data(): + n = 8760 + time = pd.date_range(start='2024-01-01', freq='h', periods=n) + + cov = [[1, 0.7], [0.7, 1]] + mean = [0, 5] + + df = np.random.multivariate_normal(cov=cov, mean=mean, size=n) + df[:, 1] *= 2 + + df[6000:7000, 1] += 2 + + return pd.DataFrame(df, columns=['a', 'b'], index=time) + + +def test_time_series_normalizer_normalize(sample_data): + tsn = TimeSeriesNormalizer(freq_trend='1d') + trend = tsn.normalize(sample_data, target='b') + + assert isinstance(trend, pd.Series) + assert len(trend) == len(sample_data) + assert trend.index.equals(sample_data.index) + + +def test_time_series_normalizer_output_shape(sample_data): + tsn = TimeSeriesNormalizer(freq_trend='1d') + trend = tsn.normalize(sample_data, target='b') + + assert trend.shape == (8760,) + + +def test_time_series_normalizer_with_different_freq(sample_data): + tsn_hourly = TimeSeriesNormalizer(freq_trend='1h') + tsn_daily = TimeSeriesNormalizer(freq_trend='1d') + + trend_hourly = tsn_hourly.normalize(sample_data, target='b') + trend_daily = tsn_daily.normalize(sample_data, target='b') + + assert not np.allclose(trend_hourly, trend_daily) # The trends should be different diff --git a/tests/test_xgbwrapper.py b/tests/test_xgbwrapper.py index 007798d..8a70ad7 100644 --- a/tests/test_xgbwrapper.py +++ b/tests/test_xgbwrapper.py @@ -4,7 +4,8 @@ import shap from sklearn.datasets import load_diabetes -from apyxl import MissingInputError, NotFittedError, XGBRegressorWrapper +from apyxl import XGBRegressorWrapper +from apyxl._misc import MissingInputError, NotFittedError @pytest.fixture