8000 TST Replace assert_warns from decomposition/tests (#20214) · scikit-learn/scikit-learn@9884ccd · GitHub
[go: up one dir, main page]

Skip to content

Commit 9884ccd

Browse files
author
Nanshan Li
authored
TST Replace assert_warns from decomposition/tests (#20214)
1 parent 36915ae commit 9884ccd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sklearn/decomposition/tests/test_fastica.py

Lines changed: 11 additions & 5 deletions
@pytest.mark.parametrize('add_noise', [True, False])
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from sklearn.utils._testing import assert_almost_equal
1212
from sklearn.utils._testing import assert_array_almost_equal
13-
from sklearn.utils._testing import assert_warns
1413

1514
from sklearn.decomposition import FastICA, fastica, PCA
1615
from sklearn.decomposition._fastica import _gs_decorrelation
@@ -141,7 +140,9 @@ def test_fastica_nowhiten():
141140

142141
# test for issue #697
143142
ica = FastICA(n_components=1, whiten=False, random_state=0)
144-
assert_warns(UserWarning, ica.fit, m)
143+
warn_msg = "Ignoring n_components with whiten=False."
144+
with pytest.warns(UserWarning, match=warn_msg):
145+
ica.fit(m)
145146
assert hasattr(ica, 'mixing_')
146147

147148

@@ -164,9 +165,14 @@ def test_fastica_convergence_fail():
164165
m = np.dot(mixing, s)
165166

166167
# Do fastICA with tolerance 0. to ensure failing convergence
167-
ica = FastICA(algorithm="parallel", n_components=2, random_state=rng,
168-
max_iter=2, tol=0.)
169-
assert_warns(ConvergenceWarning, ica.fit, m.T)
168+
warn_msg = (
169+
"FastICA did not converge. Consider increasing tolerance "
170+
"or the maximum number of iterations."
171+
)
172+
with pytest.warns(ConvergenceWarning, match=warn_msg):
173+
ica = FastICA(algorithm="parallel", n_components=2, random_state=rng,
174+
max_iter=2, tol=0.)
175+
ica.fit(m.T)
170176

171177

172178

0 commit comments

Comments
 (0)
0