|
6 | 6 | # Alexandre Gramfort <[email protected]> |
7 | 7 | # License: BSD 3 clause |
8 | 8 |
|
| 9 | +import pytest |
| 10 | + |
9 | 11 | import numpy as np |
10 | 12 |
|
11 | 13 | from sklearn.utils.fixes import euler_gamma |
|
15 | 17 | from sklearn.utils.testing import assert_raises |
16 | 18 | from sklearn.utils.testing import assert_warns_message |
17 | 19 | from sklearn.utils.testing import assert_equal |
18 | | -from sklearn.utils.testing import assert_no_warnings |
19 | 20 | from sklearn.utils.testing import assert_greater |
20 | 21 | from sklearn.utils.testing import ignore_warnings |
21 | 22 |
|
@@ -105,8 +106,20 @@ def test_iforest_error(): |
105 | 106 | assert_warns_message(UserWarning, |
106 | 107 | "max_samples will be set to n_samples for estimation", |
107 | 108 | 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 | + |
110 | 123 | assert_raises(ValueError, IsolationForest(max_samples='foobar').fit, X) |
111 | 124 | assert_raises(ValueError, IsolationForest(max_samples=1.5).fit, X) |
112 | 125 |
|
|
0 commit comments