Skip to content

Commit

Permalink
remove legacy adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyBagnall committed Jul 13, 2024
1 parent 3a01b53 commit a19b90b
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 152 deletions.
2 changes: 1 addition & 1 deletion aeon/classification/compose/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from aeon.testing.mock_estimators import MockCollectionTransformer
from aeon.testing.utils.estimator_checks import _assert_array_almost_equal
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.collection import (
AutocorrelationFunctionTransformer,
HOG1DTransformer,
Expand Down
2 changes: 1 addition & 1 deletion aeon/clustering/compose/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from aeon.testing.mock_estimators import MockCollectionTransformer
from aeon.testing.utils.estimator_checks import _assert_array_almost_equal
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.collection import (
AutocorrelationFunctionTransformer,
HOG1DTransformer,
Expand Down
6 changes: 3 additions & 3 deletions aeon/forecasting/base/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __mul__(self, other):
not nested, contains only non-TransformerPipeline `aeon` transformers
"""
from aeon.forecasting.compose import TransformedTargetForecaster
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.base import BaseTransformer
from aeon.utils.sklearn import is_sklearn_transformer

Expand Down Expand Up @@ -155,7 +155,7 @@ def __rmul__(self, other):
not nested, contains only non-TransformerPipeline `aeon` steps
"""
from aeon.forecasting.compose import TransformedTargetForecaster
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.base import BaseTransformer
from aeon.utils.sklearn import is_sklearn_transformer

Expand Down Expand Up @@ -186,7 +186,7 @@ def __rpow__(self, other):
not nested, contains only non-TransformerPipeline `aeon` steps
"""
from aeon.forecasting.compose import ForecastingPipeline
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.base import BaseTransformer
from aeon.utils.sklearn import is_sklearn_transformer

Expand Down
2 changes: 1 addition & 1 deletion aeon/forecasting/compose/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def get_test_params(cls, parameter_set="default"):
from aeon.forecasting.compose._reduce import DirectReductionForecaster
from aeon.forecasting.naive import NaiveForecaster
from aeon.testing.mock_estimators import MockTransformer
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.detrend import Detrender

# StandardScaler does not skip fit, NaiveForecaster is not probabilistic
Expand Down
2 changes: 1 addition & 1 deletion aeon/forecasting/compose/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from aeon.testing.data_generation._legacy import get_examples, make_series
from aeon.testing.mock_estimators import MockForecaster, MockTransformer
from aeon.testing.utils.estimator_checks import _assert_array_almost_equal
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.detrend import Detrender
from aeon.transformations.hierarchical.aggregate import Aggregator
from aeon.transformations.impute import Imputer
Expand Down
2 changes: 1 addition & 1 deletion aeon/regression/compose/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from aeon.testing.mock_estimators import MockCollectionTransformer
from aeon.testing.utils.estimator_checks import _assert_array_almost_equal
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.collection import (
AutocorrelationFunctionTransformer,
HOG1DTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,142 +224,3 @@ def get_test_params(cls, parameter_set="default"):
params2 = {"transformer": StandardScaler(), "fit_in_transform": True}

return [params1, params2]


# TODO: remove in v0.11.0
@deprecated(
version="0.10.0",
reason="PandasTransformAdaptor will be removed in version 0.11.0.",
category=FutureWarning,
)
class PandasTransformAdaptor(BaseTransformer):
"""
Adapt pandas transformations to aeon interface.
In `transform`, executes `pd.DataFrame` method of name `method` on data,
optionally with keywords arguments passed, via `kwargs` hyper-parameter.
The `apply_to` parameter controls what the data is upon which `method` is called:
"call" = for `X` seen in `transform`, "all"/"all_subset" = all data seen so far.
See below for details.
For hierarchical series, operation is applied by instance.
Parameters
----------
method : str, optional, default = None = identity transform
Name of the method of DataFrame that is applied in transform.
kwargs : dict, optional, default = empty dict (no kwargs passed to method)
Arguments passed to DataFrame.method.
apply_to : str, one of "call", "all", "all_subset", optional, default = "call"
"call" = method is applied to `X` seen in transform only
"all" = method is applied to all `X` seen in `fit`, `update`, `transform`
more precisely, the application to `self._X` is returned
"all_subset" = method is applied to all `X` like for "all" value,
but before returning, result is sub-set to indices of `X` in `transform`
in "all", "all_subset", `X` seen in `transform` do not update `self._X`.
"""

_tags = {
"input_data_type": "Series",
# what is the abstract type of X: Series, or Panel
"output_data_type": "Series",
# what abstract type is returned: Primitives, Series, Panel
"instancewise": True,
"X_inner_type": "pd.DataFrame",
"y_inner_type": "None",
"capability:multivariate": True,
"transform-returns-same-time-index": False,
"fit_is_empty": False,
"capability:inverse_transform": False,
"remember_data": False,
}

def __init__(self, method, kwargs=None, apply_to="call"):
self.method = method
self.kwargs = kwargs
self.apply_to = apply_to

if not isinstance(apply_to, str):
raise TypeError(
f"apply_to parameter must be a str, but found {type(apply_to)}"
)
if apply_to not in ["call", "all", "all_subset"]:
raise ValueError(
'apply_to must be one of "call", "all", "all_subset", '
f'but found "{apply_to}"'
)

super().__init__()

if apply_to in ["all", "all_subset"]:
self.set_tags(**{"remember_data": True})

if apply_to == "all_subset":
self.set_tags(**{"transform-returns-same-time-index": True})

if apply_to == "call":
self.set_tags(**{"fit_is_empty": True})

def _transform(self, X, y=None):
"""Transform X and return a transformed version.
private _transform containing the core logic, called from transform
Parameters
----------
X : pd.DataFrame
Data to be transformed
y : ignored argument for interface compatibility
Additional data, e.g., labels for transformation
Returns
-------
Xt : pd.DataFrame
transformed version of X
"""
apply_to = self.apply_to
method = self.method
kwargs = self.kwargs

if kwargs is None:
kwargs = {}

if apply_to in ["all", "all_subset"]:
_X = X.combine_first(self._X)
else:
_X = X

Xt = getattr(_X, method)(**kwargs)

if apply_to in ["all_subset"]:
Xt = Xt.loc[X.index]

return Xt

@classmethod
def get_test_params(cls, parameter_set="default"):
"""Return testing parameter settings for the estimator.
Parameters
----------
parameter_set : str, default="default"
Name of the set of test parameters to return, for use in tests. If no
special parameters are defined for a value, will return `"default"` set.
Returns
-------
params : dict or list of dict, default = {}
Parameters to create testing instances of the class
Each dict are parameters to construct an "interesting" test instance, i.e.,
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
`create_test_instance` uses the first (or only) dictionary in `params`
"""
params1 = {"method": "diff"}
params2 = {"method": "diff", "kwargs": {"periods": 2}, "apply_to": "all_subset"}
params3 = {
"method": "shift",
"kwargs": {"periods": 12},
"apply_to": "all",
}

return [params1, params2, params3]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from aeon.testing.mock_estimators import MockCollectionTransformer
from aeon.testing.utils.estimator_checks import _assert_array_almost_equal
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.collection import (
AutocorrelationFunctionTransformer,
HOG1DTransformer,
Expand Down
2 changes: 1 addition & 1 deletion aeon/transformations/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

def _coerce_to_aeon(other):
"""Check and format inputs to dunders for compose."""
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor

# if sklearn transformer, adapt to aeon transformer first
if is_sklearn_transformer(other):
Expand Down
2 changes: 1 addition & 1 deletion aeon/transformations/tests/test_optionalpassthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_optionalpassthrough():
SlidingWindowSplitter,
)
from aeon.forecasting.naive import NaiveForecaster
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.compose import OptionalPassthrough
from aeon.transformations.detrend import Deseasonalizer

Expand Down
2 changes: 1 addition & 1 deletion aeon/transformations/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sklearn.tree import DecisionTreeClassifier

from aeon.testing.data_generation import make_example_nested_dataframe
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor
from aeon.transformations.collection.segment import RandomIntervalSegmenter

# load data
Expand Down
2 changes: 1 addition & 1 deletion aeon/transformations/tests/test_sklearn_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sklearn.preprocessing import PowerTransformer

from aeon.datasets import load_airline
from aeon.transformations.adapt import TabularToSeriesAdaptor
from aeon.transformations._legacy.adapt import TabularToSeriesAdaptor


def test_boxcox_transform():
Expand Down

0 comments on commit a19b90b

Please sign in to comment.