From 95c5b606b687b4d5d56ed72caa9e774cdb080c40 Mon Sep 17 00:00:00 2001 From: Nanshan Li Date: Sun, 6 Jun 2021 21:33:07 +0800 Subject: [PATCH 1/2] Remove assert_warns from test_fastica.py --- sklearn/decomposition/tests/test_fastica.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sklearn/decomposition/tests/test_fastica.py b/sklearn/decomposition/tests/test_fastica.py index 9f37ac25c2f76..e5dcfb43581d0 100644 --- a/sklearn/decomposition/tests/test_fastica.py +++ b/sklearn/decomposition/tests/test_fastica.py @@ -10,7 +10,6 @@ from sklearn.utils._testing import assert_almost_equal from sklearn.utils._testing import assert_array_almost_equal -from sklearn.utils._testing import assert_warns from sklearn.decomposition import FastICA, fastica, PCA from sklearn.decomposition._fastica import _gs_decorrelation @@ -141,7 +140,9 @@ def test_fastica_nowhiten(): # test for issue #697 ica = FastICA(n_components=1, whiten=False, random_state=0) - assert_warns(UserWarning, ica.fit, m) + warn_msg = "Ignoring n_components with whiten=False." + with pytest.warns(UserWarning, match=warn_msg): + ica.fit(m) assert hasattr(ica, 'mixing_') @@ -164,9 +165,11 @@ def test_fastica_convergence_fail(): m = np.dot(mixing, s) # Do fastICA with tolerance 0. to ensure failing convergence - ica = FastICA(algorithm="parallel", n_components=2, random_state=rng, - max_iter=2, tol=0.) - assert_warns(ConvergenceWarning, ica.fit, m.T) + warn_msg = "FastICA did not converge. Consider increasing tolerance or the maximum number of iterations." + with pytest.warns(ConvergenceWarning, match=warn_msg): + ica = FastICA(algorithm="parallel", n_components=2, random_state=rng, + max_iter=2, tol=0.) + ica.fit(m.T) @pytest.mark.parametrize('add_noise', [True, False]) From 9c28549ed581b9f52de800f08137cc4ec7c545e5 Mon Sep 17 00:00:00 2001 From: Nanshan Li Date: Sun, 6 Jun 2021 22:03:31 +0800 Subject: [PATCH 2/2] lint --- sklearn/decomposition/tests/test_fastica.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sklearn/decomposition/tests/test_fastica.py b/sklearn/decomposition/tests/test_fastica.py index e5dcfb43581d0..4379b07697d0c 100644 --- a/sklearn/decomposition/tests/test_fastica.py +++ b/sklearn/decomposition/tests/test_fastica.py @@ -165,10 +165,13 @@ def test_fastica_convergence_fail(): m = np.dot(mixing, s) # Do fastICA with tolerance 0. to ensure failing convergence - warn_msg = "FastICA did not converge. Consider increasing tolerance or the maximum number of iterations." + warn_msg = ( + "FastICA did not converge. Consider increasing tolerance " + "or the maximum number of iterations." + ) with pytest.warns(ConvergenceWarning, match=warn_msg): ica = FastICA(algorithm="parallel", n_components=2, random_state=rng, - max_iter=2, tol=0.) + max_iter=2, tol=0.) ica.fit(m.T)