Skip to content

Commit

Permalink
correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilJl committed Oct 4, 2024
1 parent 2a94b88 commit 194f243
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
47 changes: 47 additions & 0 deletions tests/test_timeseriesnormalizer.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/test_xgbwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 194f243

Please sign in to comment.