Skip to content

Commit

Permalink
Add a test_mstl module checking if transform returns desired comp…
Browse files Browse the repository at this point in the history
…onents (#6084)

Closes #6083, resolves #5458.

This PR adds a test file for the
[MSTL](https://github.com/sktime/sktime/blob/main/sktime/transformations/series/detrend/mstl.py)
class. Currently, all it intends to do is test whether
[MSTL](https://github.com/sktime/sktime/blob/main/sktime/transformations/series/detrend/mstl.py)'s
`transform` returns the correct components when `return_components` is
set to True during initialization.

If it would be beneficial, I could probably expand the testing script to
test MSTL in other scenarios (like we do for `_detrender` and
`_deseasonalizer`). From @fkiraly's last comment in #5458, I thought
this would be the most immediately helpful and nice-to-have test.

There's just one method in my code right now so it should be quick to
review. This is my first PR here and I'm still familiarizing myself with
the codebase, so any feedback would help.
  • Loading branch information
kcentric committed Mar 15, 2024
1 parent 50b0116 commit c5af6ea
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions sktime/transformations/series/detrend/tests/test_mstl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)
"""Tests MSTL functionality."""

__author__ = ["krishna-t"]

import pytest

from sktime.datasets import load_airline
from sktime.tests.test_switch import run_test_for_class
from sktime.transformations.series.detrend.mstl import MSTL


@pytest.mark.skipif(
not run_test_for_class([MSTL]),
reason="run test only if softdeps are present and incrementally (if requested)",
)
def test_transform_returns_correct_components():
"""Tests if expected components are returned when return_components=True."""
# Load our default test dataset
series = load_airline()
series.index = series.index.to_timestamp()

# Initialize the MSTL transformer with specific parameters
transformer = MSTL(periods=[3, 12], return_components=True)

# Fit the transformer to the data
transformer.fit(series)

# Transform the data
transformed = transformer.transform(series)

# Check if the transformed data has the expected components
assert "transformed" in transformed.columns, (
"Test of MSTL.transform failed with return_components=True, "
"returned DataFrame columns are missing 'transformed' "
"variable."
)
assert "trend" in transformed.columns, (
"Test of MSTL.transform failed with return_components=True, "
"returned DataFrame columns are missing 'trend' variable."
)
assert "resid" in transformed.columns, (
"Test of MSTL.transform failed with return_components=True, "
"returned DataFrame columns are missing 'resid' variable."
)
assert "seasonal_3" in transformed.columns, (
"Test of MSTL.transform failed with return_components=True, "
"returned DataFrame columns are missing 'seasonal_3 "
"variable."
)
assert "seasonal_12" in transformed.columns, (
"Test of MSTL.transform failed with return_components=True, "
"returned DataFrame columns are missing 'seasonal_12' "
"variable."
)

0 comments on commit c5af6ea

Please sign in to comment.