Skip to content

Commit

Permalink
[MNT] 0.25.0 deprecations and change actions (#5613)
Browse files Browse the repository at this point in the history
Carries out deprecations and change actions scheduled for 0.25.0:

* remove deprecated `forecasting.model_selection._split` module
* in forecasting `evaluate`, change order of return data frame
* in forecasting `evaluate`, remove `compute` arg. `kwargs` are still
accepted, with warning message. Bumped removal to 0.26.0 for smoother
transition.
* bump checks
  • Loading branch information
fkiraly committed Dec 25, 2023
1 parent b937b1e commit b595959
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 133 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -169,8 +169,8 @@ flexible choice of soft dependencies is unavailable via `conda`)
``` python
from sktime.datasets import load_airline
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.theta import ThetaForecaster
from sktime.split import temporal_train_test_split
from sktime.performance_metrics.forecasting import mean_absolute_percentage_error

y = load_airline()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/get_started.rst
Expand Up @@ -75,9 +75,9 @@ Forecasting
>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.base import ForecastingHorizon
>>> from sktime.forecasting.model_selection import temporal_train_test_split
>>> from sktime.forecasting.theta import ThetaForecaster
>>> from sktime.performance_metrics.forecasting import mean_absolute_percentage_error
>>> from sktime.split import temporal_train_test_split
>>> y = load_airline()
>>> y_train, y_test = temporal_train_test_split(y)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/introduction.rst
Expand Up @@ -31,8 +31,8 @@ can simply write:
from sktime.datasets import load_airline
from sktime.forecasting.compose import make_reduction
from sklearn.ensemble import RandomForestRegressor
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.performance_metrics.forecasting import MeanAbsolutePercentageError
from sktime.split import temporal_train_test_split
y = load_airline()
y_train, y_test = temporal_train_test_split(y)
Expand Down
Expand Up @@ -20,7 +20,7 @@
from sktime.utils.validation.panel import check_X


# TODO: fix this in 0.25.0
# TODO: fix this in 0.26.0
# base class should have been changed to BaseEarlyClassifier
class ProbabilityThresholdEarlyClassifier(BaseClassifier):
"""Probability Threshold Early Classifier.
Expand Down
14 changes: 7 additions & 7 deletions sktime/forecasting/all/__init__.py
Expand Up @@ -11,13 +11,6 @@
from sktime.datasets import load_airline, load_longley, load_lynx, load_shampoo_sales
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.model_evaluation import evaluate
from sktime.forecasting.model_selection import (
CutoffSplitter,
ExpandingWindowSplitter,
SingleWindowSplitter,
SlidingWindowSplitter,
temporal_train_test_split,
)
from sktime.performance_metrics.forecasting import (
GeometricMeanRelativeAbsoluteError,
GeometricMeanRelativeSquaredError,
Expand Down Expand Up @@ -58,6 +51,13 @@
relative_loss,
)
from sktime.registry import all_estimators
from sktime.split import (
CutoffSplitter,
ExpandingWindowSplitter,
SingleWindowSplitter,
SlidingWindowSplitter,
temporal_train_test_split,
)
from sktime.transformations.series.detrend import Deseasonalizer, Detrender
from sktime.utils.plotting import plot_series

Expand Down
2 changes: 1 addition & 1 deletion sktime/forecasting/base/_fh.py
Expand Up @@ -806,7 +806,7 @@ def _to_relative(fh: ForecastingHorizon, cutoff=None) -> ForecastingHorizon:
absolute = _coerce_to_period(absolute, freq=fh.freq)
cutoff = _coerce_to_period(cutoff, freq=fh.freq)

# TODO: 0.25.0:
# TODO: 0.26.0:
# Check at every minor release whether lower pandas bound >=0.15.0
# if yes, can remove the workaround in the "else" condition and the check
#
Expand Down
2 changes: 1 addition & 1 deletion sktime/forecasting/compose/_pipeline.py
Expand Up @@ -170,7 +170,7 @@ def _get_inverse_transform(self, transformers, y, X=None, mode=None):
if len(levels) == 1:
levels = levels[0]
yt[ix] = y.xs(ix, level=levels, axis=1)
# todo 0.25.0 - check why this cannot be easily removed
# todo 0.26.0 - check why this cannot be easily removed
# in theory, we should get rid of the "Coverage" case treatment
# (the legacy naming convention was removed in 0.23.0)
# deal with the "Coverage" case, we need to get rid of this
Expand Down
2 changes: 1 addition & 1 deletion sktime/forecasting/compose/tests/test_pipeline.py
Expand Up @@ -485,7 +485,7 @@ def test_forecastx_logic():
)
def test_forecastx_fit_behavior():
from sktime.forecasting.compose import ForecastX
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.split import temporal_train_test_split

y, X = load_longley()
y_train, y_test, X_train, X_test = temporal_train_test_split(y, X)
Expand Down
47 changes: 2 additions & 45 deletions sktime/forecasting/model_evaluation/_functions.py
Expand Up @@ -318,8 +318,6 @@ def _evaluate_window(x, meta):
return result


# todo 0.25.0: remove compute argument and docstring
# todo 0.25.0: remove kwargs and docstring
def evaluate(
forecaster,
cv,
Expand All @@ -330,7 +328,6 @@ def evaluate(
return_data: bool = False,
error_score: Union[str, int, float] = np.nan,
backend: Optional[str] = None,
compute: bool = None,
cv_X=None,
backend_params: Optional[dict] = None,
**kwargs,
Expand Down Expand Up @@ -422,9 +419,6 @@ def evaluate(
"threading" is unlikely to see speed ups due to the GIL and the serialization
backend (``cloudpickle``) for "dask" and "loky" is generally more robust
than the standard ``pickle`` library used in "multiprocessing".
compute : bool, default=True, deprecated and will be removed in 0.25.0.
If backend="dask", whether returned DataFrame is computed.
If set to True, returns `pd.DataFrame`, otherwise `dask.dataframe.DataFrame`.
cv_X : sktime BaseSplitter descendant, optional
determines split of ``X`` into test and train folds
default is ``X`` being split to identical ``loc`` indices as ``y``
Expand Down Expand Up @@ -525,10 +519,10 @@ def evaluate(
"installed, but dask is not present in the python environment"
)

# todo 0.25.0: remove kwargs and this warning
# todo 0.26.0: remove kwargs and this warning
if kwargs != {}:
warnings.warn(
"in evaluate, kwargs will no longer be supported from sktime 0.25.0. "
"in evaluate, kwargs are no longer supported. "
"to pass configuration arguments to the parallelization backend, "
"use backend_params instead. "
f"The following kwargs were found: {kwargs.keys()}, pass these as "
Expand All @@ -537,28 +531,8 @@ def evaluate(
stacklevel=2,
)

# todo 0.25.0: remove compute argument and logic, and remove this warning
if compute is not None:
warnings.warn(
"the compute argument of evaluate is deprecated and will be removed "
"in sktime 0.25.0. For the same behaviour in the future, "
'use backend="dask_lazy"',
DeprecationWarning,
stacklevel=2,
)
if compute is None:
compute = True
if backend == "dask" and not compute:
backend = "dask_lazy"

_check_strategy(strategy)
cv = check_cv(cv, enforce_start_with_window=True)
# TODO: remove lines(four lines below) and 599-612 in v0.25.0
if isinstance(scoring, list):
raise_warn, num = True, len(scoring)
else:
raise_warn, num = False, 1
# removal until here
scoring = _check_scores(scoring)

ALLOWED_SCITYPES = ["Series", "Panel", "Hierarchical"]
Expand Down Expand Up @@ -669,21 +643,4 @@ def gen_y_X_train_test(y, X, cv, cv_X):
# final formatting of results DataFrame
results = results.reset_index(drop=True)

# TODO: remove 16 lines below and 451-455 in v0.25.0
if raise_warn:
warnings.warn(
"Starting v0.25.0 model_evaluation.evaluate module will rearrange "
"all metric columns to the left of its output result DataFrame. "
"Please use loc references when addressing the columns. You can "
"safely ignore this warning if you don't use evaluate function directly.",
DeprecationWarning,
stacklevel=2,
)
columns = results.columns.to_list()
non_first_metrics = []
for _ in range(1, num):
metric = columns.pop(1)
non_first_metrics.append(metric)
results = results.reindex(columns=columns + non_first_metrics)
# removal until here
return results
18 changes: 0 additions & 18 deletions sktime/forecasting/model_selection/__init__.py
Expand Up @@ -4,29 +4,11 @@

__author__ = ["mloning", "kkoralturk"]
__all__ = [
"CutoffSplitter",
"SameLocSplitter",
"SingleWindowSplitter",
"SlidingWindowSplitter",
"temporal_train_test_split",
"ExpandingGreedySplitter",
"ExpandingWindowSplitter",
"TestPlusTrainSplitter",
"ForecastingGridSearchCV",
"ForecastingRandomizedSearchCV",
"ForecastingSkoptSearchCV",
]

from sktime.forecasting.model_selection._split import (
CutoffSplitter,
ExpandingGreedySplitter,
ExpandingWindowSplitter,
SameLocSplitter,
SingleWindowSplitter,
SlidingWindowSplitter,
TestPlusTrainSplitter,
temporal_train_test_split,
)
from sktime.forecasting.model_selection._tune import (
ForecastingGridSearchCV,
ForecastingRandomizedSearchCV,
Expand Down
42 changes: 0 additions & 42 deletions sktime/forecasting/model_selection/_split.py

This file was deleted.

4 changes: 1 addition & 3 deletions sktime/forecasting/model_selection/_tune.py
Expand Up @@ -544,9 +544,7 @@ class ForecastingGridSearchCV(BaseGridSearch):
--------
>>> from sktime.datasets import load_shampoo_sales
>>> from sktime.forecasting.model_selection import ForecastingGridSearchCV
>>> from sktime.split import (
... ExpandingWindowSplitter,
... ExpandingWindowSplitter)
>>> from sktime.split import ExpandingWindowSplitter
>>> from sktime.forecasting.naive import NaiveForecaster
>>> y = load_shampoo_sales()
>>> fh = [1,2,3]
Expand Down
2 changes: 1 addition & 1 deletion sktime/forecasting/trend/_pwl_trend_forecaster.py
Expand Up @@ -60,8 +60,8 @@ class ProphetPiecewiseLinearTrendForecaster(_ProphetAdapter):
--------
>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.trend import ProphetPiecewiseLinearTrendForecaster
>>> from sktime.forecasting.model_selection import temporal_train_test_split
>>> from sktime.forecasting.base import ForecastingHorizon
>>> from sktime.split import temporal_train_test_split
>>> y =load_airline().to_timestamp(freq='M')
>>> y_train, y_test = temporal_train_test_split(y)
>>> fh = ForecastingHorizon(y.index, is_relative=False)
Expand Down
2 changes: 1 addition & 1 deletion sktime/forecasting/trend/tests/test_pwl_trend.py
Expand Up @@ -11,11 +11,11 @@

from sktime.datasets import load_airline
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.trend import (
PolynomialTrendForecaster,
ProphetPiecewiseLinearTrendForecaster,
)
from sktime.split import temporal_train_test_split
from sktime.tests.test_switch import run_test_for_class


Expand Down
5 changes: 1 addition & 4 deletions sktime/split/sameloc.py
Expand Up @@ -141,10 +141,7 @@ def get_test_params(cls, parameter_set="default"):
`create_test_instance` uses the first (or only) dictionary in `params`
"""
from sktime.datasets import load_airline
from sktime.forecasting.model_selection import (
ExpandingWindowSplitter,
SingleWindowSplitter,
)
from sktime.split import ExpandingWindowSplitter, SingleWindowSplitter

y = load_airline()
y_temp = y[:60]
Expand Down
2 changes: 1 addition & 1 deletion sktime/split/temporal_train_test_split.py
Expand Up @@ -91,8 +91,8 @@ def temporal_train_test_split(
Examples
--------
>>> from sktime.forecasting.model_selection import temporal_train_test_split
>>> from sktime.datasets import load_airline, load_osuleaf
>>> from sktime.split import temporal_train_test_split
>>> from sktime.utils._testing.panel import _make_panel
>>> # univariate time series
>>> y = load_airline()
Expand Down
5 changes: 1 addition & 4 deletions sktime/split/testplustrain.py
Expand Up @@ -131,10 +131,7 @@ def get_test_params(cls, parameter_set="default"):
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
`create_test_instance` uses the first (or only) dictionary in `params`
"""
from sktime.forecasting.model_selection import (
ExpandingWindowSplitter,
SingleWindowSplitter,
)
from sktime.split import ExpandingWindowSplitter, SingleWindowSplitter

cv_1 = ExpandingWindowSplitter(fh=[2, 4], initial_window=24, step_length=12)
cv_2 = SingleWindowSplitter(fh=[2, 4], window_length=24)
Expand Down

0 comments on commit b595959

Please sign in to comment.