From d91c118e0110767859bc6d616fd36640e6d076a5 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Mon, 7 Aug 2023 14:14:11 -0400 Subject: [PATCH] MNT Use assert_no_warnings from numpy.testing --- sklearn/utils/_testing.py | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/sklearn/utils/_testing.py b/sklearn/utils/_testing.py index 8b54df9f25b72..bf558ff7e6dd4 100644 --- a/sklearn/utils/_testing.py +++ b/sklearn/utils/_testing.py @@ -38,6 +38,7 @@ assert_array_almost_equal, assert_array_equal, assert_array_less, + assert_no_warnings, ) import sklearn @@ -65,6 +66,7 @@ "assert_approx_equal", "assert_allclose", "assert_run_python_script", + "assert_no_warnings", "SkipTest", ] @@ -80,32 +82,6 @@ assert_raises_regexp = assert_raises_regex -# To remove when we support numpy 1.7 -def assert_no_warnings(func, *args, **kw): - """ - Parameters - ---------- - func - *args - **kw - """ - # very important to avoid uncontrolled state propagation - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - - result = func(*args, **kw) - if hasattr(np, "FutureWarning"): - # Filter out numpy-specific warnings in numpy >= 1.9 - w = [e for e in w if e.category is not np.VisibleDeprecationWarning] - - if len(w) > 0: - raise AssertionError( - "Got warnings when calling %s: [%s]" - % (func.__name__, ", ".join(str(warning) for warning in w)) - ) - return result - - def ignore_warnings(obj=None, category=Warning): """Context manager and decorator to ignore warnings.