Skip to content

Commit 60f887e

Browse files
lestevejnothman
authored andcommitted
MAINT Fix scipy-dev-wheels build (scikit-learn#11251)
Ignore PendingDeprecationWarning
1 parent 97a15db commit 60f887e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

sklearn/ensemble/tests/test_iforest.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# Alexandre Gramfort <[email protected]>
77
# License: BSD 3 clause
88

9+
import pytest
10+
911
import numpy as np
1012

1113
from sklearn.utils.fixes import euler_gamma
@@ -15,7 +17,6 @@
1517
from sklearn.utils.testing import assert_raises
1618
from sklearn.utils.testing import assert_warns_message
1719
from sklearn.utils.testing import assert_equal
18-
from sklearn.utils.testing import assert_no_warnings
1920
from sklearn.utils.testing import assert_greater
2021
from sklearn.utils.testing import ignore_warnings
2122

@@ -105,8 +106,20 @@ def test_iforest_error():
105106
assert_warns_message(UserWarning,
106107
"max_samples will be set to n_samples for estimation",
107108
IsolationForest(max_samples=1000).fit, X)
108-
assert_no_warnings(IsolationForest(max_samples='auto').fit, X)
109-
assert_no_warnings(IsolationForest(max_samples=np.int64(2)).fit, X)
109+
# note that assert_no_warnings does not apply since it enables a
110+
# PendingDeprecationWarning triggered by scipy.sparse's use of
111+
# np.matrix. See issue #11251.
112+
with pytest.warns(None) as record:
113+
IsolationForest(max_samples='auto').fit(X)
114+
user_warnings = [each for each in record
115+
if issubclass(each.category, UserWarning)]
116+
assert len(user_warnings) == 0
117+
with pytest.warns(None) as record:
118+
IsolationForest(max_samples=np.int64(2)).fit(X)
119+
user_warnings = [each for each in record
120+
if issubclass(each.category, UserWarning)]
121+
assert len(user_warnings) == 0
122+
110123
assert_raises(ValueError, IsolationForest(max_samples='foobar').fit, X)
111124
assert_raises(ValueError, IsolationForest(max_samples=1.5).fit, X)
112125

0 commit comments

Comments
 (0)