From 8c9ea538e549db344871077c8d563fca27e54f23 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 14 Oct 2022 11:22:46 +0200 Subject: [PATCH 1/2] cln deprecations --- sklearn/base.py | 5 ++--- sklearn/tests/test_base.py | 2 +- sklearn/utils/estimator_checks.py | 18 +++++------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/sklearn/base.py b/sklearn/base.py index 0bd9327c38166..3ef2a908cdadf 100644 --- a/sklearn/base.py +++ b/sklearn/base.py @@ -417,8 +417,7 @@ def _check_feature_names(self, X, *, reset): fitted_feature_names != X_feature_names ): message = ( - "The feature names should match those that were " - "passed during fit. Starting version 1.2, an error will be raised.\n" + "The feature names should match those that were passed during fit.\n" ) fitted_feature_names_set = set(fitted_feature_names) X_feature_names_set = set(X_feature_names) @@ -449,7 +448,7 @@ def add_names(names): "Feature names must be in the same order as they were in fit.\n" ) - warnings.warn(message, FutureWarning) + raise ValueError(message) def _validate_data( self, diff --git a/sklearn/tests/test_base.py b/sklearn/tests/test_base.py index 6e17721046e9b..934bf7719163c 100644 --- a/sklearn/tests/test_base.py +++ b/sklearn/tests/test_base.py @@ -615,7 +615,7 @@ def transform(self, X): trans.fit(df) msg = "The feature names should match those that were passed" df_bad = pd.DataFrame(X_np, columns=iris.feature_names[::-1]) - with pytest.warns(FutureWarning, match=msg): + with pytest.raises(ValueError, match=msg): trans.transform(df_bad) # warns when fitted on dataframe and transforming a ndarray diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py index 90efa06073487..1b83b686325c3 100644 --- a/sklearn/utils/estimator_checks.py +++ b/sklearn/utils/estimator_checks.py @@ -3913,22 +3913,14 @@ def check_dataframe_column_names_consistency(name, estimator_orig): X_bad = pd.DataFrame(X, columns=invalid_name) expected_msg = re.escape( - "The feature names should match those that were passed " - "during fit. Starting version 1.2, an error will be raised.\n" + "The feature names should match those that were passed during fit.\n" f"{additional_message}" ) for name, method in check_methods: - # TODO In 1.2, this will be an error. - with warnings.catch_warnings(): - warnings.filterwarnings( - "error", - category=FutureWarning, - module="sklearn", - ) - with raises( - FutureWarning, match=expected_msg, err_msg=f"{name} did not raise" - ): - method(X_bad) + with raises( + ValueError, match=expected_msg, err_msg=f"{name} did not raise" + ): + method(X_bad) # partial_fit checks on second call # Do not call partial fit if early_stopping is on From 7ef7191564a66f726362d8ae5f720f7e41fb3a39 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 14 Oct 2022 12:08:02 +0200 Subject: [PATCH 2/2] missed partial_fit check --- sklearn/utils/estimator_checks.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py index 1b83b686325c3..8a1f4eb95583a 100644 --- a/sklearn/utils/estimator_checks.py +++ b/sklearn/utils/estimator_checks.py @@ -3934,10 +3934,8 @@ def check_dataframe_column_names_consistency(name, estimator_orig): else: estimator.partial_fit(X, y) - with warnings.catch_warnings(): - warnings.filterwarnings("error", category=FutureWarning, module="sklearn") - with raises(FutureWarning, match=expected_msg): - estimator.partial_fit(X_bad, y) + with raises(ValueError, match=expected_msg): + estimator.partial_fit(X_bad, y) def check_transformer_get_feature_names_out(name, transformer_orig):