From 5a1c3abdba5d5e1d5772d89b782c827c0776a01a Mon Sep 17 00:00:00 2001 From: Thibault Cordier <124613154+thibaultcordier@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:26:39 +0100 Subject: [PATCH] UPD: add DeprecationWarning for partial_fit Co-authored-by: Vincent Blot <52573624+vincentblot28@users.noreply.github.com> --- mapie/regression/time_series_regression.py | 7 +++++++ mapie/tests/test_time_series_regression.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/mapie/regression/time_series_regression.py b/mapie/regression/time_series_regression.py index bb52a50a8..2237b7da5 100644 --- a/mapie/regression/time_series_regression.py +++ b/mapie/regression/time_series_regression.py @@ -158,6 +158,13 @@ def partial_fit( If the length of ``y`` is greater than the length of the training set. """ + warnings.warn( + "WARNING: Deprecated method. " + + "The method \"partial_fit\" is outdated. " + + "Prefer to use \"update\" instead to keep " + + "the same behavior in the future.", + DeprecationWarning + ) check_is_fitted(self, self.fit_attributes) X, y = cast(NDArray, X), cast(NDArray, y) m, n = len(X), len(self.conformity_scores_) diff --git a/mapie/tests/test_time_series_regression.py b/mapie/tests/test_time_series_regression.py index f7ce95917..1bae85c22 100644 --- a/mapie/tests/test_time_series_regression.py +++ b/mapie/tests/test_time_series_regression.py @@ -498,6 +498,16 @@ def test_aci__get_alpha_with_unknown_alpha() -> None: np.testing.assert_allclose(mapie_ts_reg.current_alpha[0.2], 0.3, rtol=1e-3) +def test_deprecated_partial_fit_warning(method: str) -> None: + """Test that a warning is raised if use partial_fit""" + mapie_ts_reg = MapieTimeSeriesRegressor(method='enbpi', cv=-1) + mapie_ts_reg.fit(X_toy, y_toy) + with pytest.warns( + DeprecationWarning, match=r".*WARNING: Deprecated method.*" + ): + mapie_ts_reg = mapie_ts_reg.partial_fit(X_toy, y_toy) + + @pytest.mark.parametrize("method", ["wrong_method"]) def test_method_error_in_update(monkeypatch: Any, method: str) -> None: """Test else condition for the method in .update"""