Skip to content

Commit

Permalink
[DEP] Deprecate simple wrapper transformers (#1494)
Browse files Browse the repository at this point in the history
* deprecate cos and sqrt transformers

* deprecate subset

* remove augmenters

* remove time binning

* sort out imports

* exponent test
  • Loading branch information
TonyBagnall authored May 20, 2024
1 parent 0e025d7 commit 5f4b8b1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 206 deletions.
25 changes: 25 additions & 0 deletions aeon/transformations/augmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import numpy as np
import pandas as pd
from deprecated.sphinx import deprecated
from scipy.stats import norm
from sklearn.utils import check_random_state

Expand All @@ -33,6 +34,12 @@ class _AugmenterTags:
}


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="WhiteNoiseAugmenter will be removed in version 0.10.",
category=FutureWarning,
)
class WhiteNoiseAugmenter(_AugmenterTags, BaseTransformer):
r"""Augmenter adding Gaussian (i.e. white) noise to the time series.
Expand Down Expand Up @@ -79,6 +86,12 @@ def _transform(self, X, y=None):
return X[0] + norm.rvs(0, scale, size=len(X), random_state=self.random_state)


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="ReverseAugmenter will be removed in version 0.10.",
category=FutureWarning,
)
class ReverseAugmenter(_AugmenterTags, BaseTransformer):
r"""Augmenter reversing the time series.
Expand Down Expand Up @@ -113,6 +126,12 @@ def _transform(self, X, y=None):
return X.loc[::-1].reset_index(drop=True, inplace=False)


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="InvertAugmenter will be removed in version 0.10.",
category=FutureWarning,
)
class InvertAugmenter(_AugmenterTags, BaseTransformer):
r"""Augmenter inverting the time series by multiplying it by -1.
Expand Down Expand Up @@ -140,6 +159,12 @@ def _transform(self, X, y=None):
return X.mul(-1)


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="RandomSamplesAugmenter will be removed in version 0.10.",
category=FutureWarning,
)
class RandomSamplesAugmenter(_AugmenterTags, BaseTransformer):
r"""Draw random samples from time series.
Expand Down
7 changes: 7 additions & 0 deletions aeon/transformations/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@

import numpy as np
import pandas as pd
from deprecated.sphinx import deprecated

from aeon.transformations.base import BaseTransformer


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="TimeBinAggregate will be removed in version 0.10.",
category=FutureWarning,
)
class TimeBinAggregate(BaseTransformer):
r"""Bins time series and aggregates by bin.
Expand Down
8 changes: 8 additions & 0 deletions aeon/transformations/cos.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
"""Implements cosine transformation."""

import numpy as np
from deprecated.sphinx import deprecated

from aeon.transformations.base import BaseTransformer

__maintainer__ = []
__all__ = ["CosineTransformer"]


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="CosineTransformer scikit wrapper will be removed in version 0.10. Please "
"just use scikit learn.",
category=FutureWarning,
)
class CosineTransformer(BaseTransformer):
"""Cosine transformation.
Expand Down
15 changes: 7 additions & 8 deletions aeon/transformations/exponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import pandas as pd
from deprecated.sphinx import deprecated

from aeon.transformations.base import BaseTransformer

Expand Down Expand Up @@ -185,6 +186,12 @@ def get_test_params(cls, parameter_set="default"):
return [{"power": 2.5, "offset": 1}, {"power": 0}]


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="SqrtTransformer will be removed in version 0.10.",
category=FutureWarning,
)
class SqrtTransformer(ExponentTransformer):
"""Apply element-sise square root transformation to a time series.
Expand Down Expand Up @@ -225,14 +232,6 @@ class SqrtTransformer(ExponentTransformer):
-----
For an input series `Z` the square root transformation is defined as
:math:`(Z + offset)^{0.5}`.
Examples
--------
>>> from aeon.transformations.exponent import SqrtTransformer
>>> from aeon.datasets import load_airline
>>> y = load_airline()
>>> transformer = SqrtTransformer()
>>> y_transform = transformer.fit_transform(y)
"""

def __init__(self, offset="auto"):
Expand Down
30 changes: 13 additions & 17 deletions aeon/transformations/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
__maintainer__ = []

import pandas as pd
from deprecated.sphinx import deprecated
from pandas.api.types import is_integer_dtype

from aeon.transformations.base import BaseTransformer


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="IndexSubset will be removed in version 0.10.",
category=FutureWarning,
)
class IndexSubset(BaseTransformer):
r"""Index subsetting transformer.
Expand All @@ -24,15 +31,6 @@ class IndexSubset(BaseTransformer):
determines which indices are kept in `Xt = transform(X, y)`
"keep" = all indices in y also appear in Xt. If not present in X, NA is filled.
"remove" = only indices that appear in both X and y are present in Xt.
Examples
--------
>>> from aeon.transformations.subset import IndexSubset
>>> from aeon.datasets import load_airline
>>> X = load_airline()[0:32]
>>> y = load_airline()[24:42]
>>> transformer = IndexSubset()
>>> X_subset = transformer.fit_transform(X=X, y=y)
"""

_tags = {
Expand Down Expand Up @@ -117,6 +115,12 @@ def get_test_params(cls, parameter_set="default"):
return [params1, params2]


# TODO: remove in v0.10.0
@deprecated(
version="0.9.0",
reason="ColumnSelect will be removed in version 0.10.",
category=FutureWarning,
)
class ColumnSelect(BaseTransformer):
r"""Column selection transformer.
Expand All @@ -138,14 +142,6 @@ class ColumnSelect(BaseTransformer):
determines which column are kept in `Xt = transform(X, y)`
"remove" = only indices that appear in both X and columns are present in Xt.
"keep" = all indices in columns appear in Xt. If not present in X, NA is filled.
Examples
--------
>>> from aeon.transformations.subset import ColumnSelect
>>> from aeon.datasets import load_longley
>>> X = load_longley()[1]
>>> transformer = ColumnSelect(columns=["GNPDEFL", "POP", "FOO"])
>>> X_subset = transformer.fit_transform(X=X)
"""

_tags = {
Expand Down
118 changes: 0 additions & 118 deletions aeon/transformations/tests/test_augmenter.py

This file was deleted.

22 changes: 9 additions & 13 deletions aeon/transformations/tests/test_exponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,30 @@
import pytest

from aeon.testing.utils.data_gen import make_series
from aeon.transformations.exponent import ExponentTransformer, SqrtTransformer
from aeon.transformations.exponent import ExponentTransformer

power_transformers = [ExponentTransformer, SqrtTransformer]


@pytest.mark.parametrize("power_transformer", power_transformers)
@pytest.mark.parametrize("_offset", ["a", [1, 2.3]])
def test_wrong_offset_type_raises_error(power_transformer, _offset):
@pytest.mark.parametrize("offset", ["a", [1, 2.3]])
def test_wrong_offset_type_raises_error(offset):
"""Test an error is raised for incorrect offset types."""
y = make_series(n_timepoints=75)

# Test input types
match = f"Expected `offset` to be int or float, but found {type(_offset)}."
match = f"Expected `offset` to be int or float, but found {type(offset)}."
with pytest.raises(ValueError, match=match):
transformer = power_transformer(offset=_offset)
transformer = ExponentTransformer(offset=offset)
transformer.fit(y)


# Test only applies to PowerTransformer b/c SqrtTransformer doesn't have power
# hyperparameter
@pytest.mark.parametrize("power_transformer", power_transformers[:1])
@pytest.mark.parametrize("_power", ["a", [1, 2.3]])
def test_wrong_power_type_raises_error(power_transformer, _power):
@pytest.mark.parametrize("power", ["a", [1, 2.3]])
def test_wrong_power_type_raises_error(power):
"""Test an error is raised for incorrect power types."""
y = make_series(n_timepoints=75)

# Test input types
match = f"Expected `power` to be int or float, but found {type(_power)}."
match = f"Expected `power` to be int or float, but found {type(power)}."
with pytest.raises(ValueError, match=match):
transformer = power_transformer(power=_power)
transformer = ExponentTransformer(power=power)
transformer.fit(y)
Loading

0 comments on commit 5f4b8b1

Please sign in to comment.