8000 MNT Use assert_no_warnings from numpy.testing (#27031) · glemaitre/scikit-learn@78b0569 · GitHub
[go: up one dir, main page]

Skip to content

Commit 78b0569

Browse files
thomasjpfanglemaitre
authored andcommitted
MNT Use assert_no_warnings from numpy.testing (scikit-learn#27031)
1 parent e6d8b49 commit 78b0569

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

sklearn/utils/_testing.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
assert_array_almost_equal,
3939
assert_array_equal,
4040
assert_array_less,
41+
assert_no_warnings,
4142
)
4243

4344
import sklearn
@@ -47,7 +48,7 @@
4748
_in_unstable_openblas_configuration,
4849
)
4950
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
5152
from sklearn.utils.multiclass import check_classification_targets
5253
from sklearn.utils.validation import (
5354
check_array,
@@ -65,6 +66,7 @@
6566
"assert_approx_equal",
6667
"assert_allclose",
6768
"assert_run_python_script",
69+
"assert_no_warnings",
6870
"SkipTest",
6971
]
7072

@@ -80,32 +82,6 @@
8082
assert_raises_regexp = assert_raises_regex
8183

8284

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-
10985
def ignore_warnings(obj=None, category=Warning):
11086
"""Context manager and decorator to ignore warnings.
11187

0 commit comments

Comments
 (0)
0