Skip to content

Commit

Permalink
Add test for different length series
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-shenshina committed Sep 24, 2021
1 parent a9fabef commit 5c18d74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,12 @@ def multitrend_df() -> pd.DataFrame:
df["segment"] = "segment_1"
df = TSDataset.to_dataset(df=df)
return df


@pytest.fixture
def ts_with_different_series_length(example_df: pd.DataFrame) -> TSDataset:
"""Generate TSDataset with different lengths series."""
df = TSDataset.to_dataset(example_df)
df.loc[:4, pd.IndexSlice["segment_1", "target"]] = None
ts = TSDataset(df=df, freq="H")
return ts
10 changes: 10 additions & 0 deletions tests/test_transforms/test_binseg_trend_transform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from copy import deepcopy
from typing import Any

import numpy as np
import pytest
from ruptures.costs import CostAR
from ruptures.costs import CostL1
Expand Down Expand Up @@ -42,3 +43,12 @@ def test_binseg_run_with_model(example_tsds: TSDataset, model: Any):
ts.fit_transform([bs])
ts.inverse_transform()
assert (ts.df == example_tsds.df).all().all()


def test_binseg_runs_with_different_series_length(ts_with_different_series_length: TSDataset):
"""Check that binseg works with datasets with different length series."""
bs = BinsegTrendTransform(in_column="target")
ts = deepcopy(ts_with_different_series_length)
ts.fit_transform([bs])
ts.inverse_transform()
np.allclose(ts.df.values, ts_with_different_series_length.df.values, equal_nan=True)

0 comments on commit 5c18d74

Please sign in to comment.