|
38 | 38 | assert_array_almost_equal,
|
39 | 39 | assert_array_equal,
|
40 | 40 | assert_array_less,
|
| 41 | + assert_no_warnings, |
41 | 42 | )
|
42 | 43 |
|
43 | 44 | import sklearn
|
|
47 | 48 | _in_unstable_openblas_configuration,
|
48 | 49 | )
|
49 | 50 | from sklearn.utils._array_api import _check_array_api_dispatch
|
50 |
| -from sklearn.utils.fixes import VisibleDeprecationWarning, threadpool_info |
| 51 | +from sklearn.utils.fixes import threadpool_info |
51 | 52 | from sklearn.utils.multiclass import check_classification_targets
|
52 | 53 | from sklearn.utils.validation import (
|
53 | 54 | check_array,
|
|
65 | 66 | "assert_approx_equal",
|
66 | 67 | "assert_allclose",
|
67 | 68 | "assert_run_python_script",
|
| 69 | + "assert_no_warnings", |
68 | 70 | "SkipTest",
|
69 | 71 | ]
|
70 | 72 |
|
|
80 | 82 | assert_raises_regexp = assert_raises_regex
|
81 | 83 |
|
82 | 84 |
|
83 |
| -# To remove when we support numpy 1.7 |
84 |
| -def assert_no_warnings(func, *args, **kw): |
85 |
| - """ |
86 |
| - Parameters |
87 |
| - ---------- |
88 |
| - func |
89 |
| - *args |
90 |
| - **kw |
91 |
| - """ |
92 |
| - # very important to avoid uncontrolled state propagation |
93 |
| - with warnings.catch_warnings(record=True) as w: |
94 |
| - warnings.simplefilter("always") |
95 |
| - |
96 |
| - result = func(*args, **kw) |
97 |
| - if hasattr(np, "FutureWarning"): |
98 |
| - # Filter out numpy-specific warnings in numpy >= 1.9 |
99 |
| - w = [e for e in w if e.category is not VisibleDeprecationWarning] |
100 |
| - |
101 |
| - if len(w) > 0: |
102 |
| - raise AssertionError( |
103 |
| - "Got warnings when calling %s: [%s]" |
104 |
| - % (func.__name__, ", ".join(str(warning) for warning in w)) |
105 |
| - ) |
106 |
| - return result |
107 |
| - |
108 |
| - |
109 | 85 | def ignore_warnings(obj=None, category=Warning):
|
110 | 86 | """Context manager and decorator to ignore warnings.
|
111 | 87 |
|
|
0 commit comments