8000 MNT Use assert_no_warnings from numpy.testing by thomasjpfan · Pull Request #27031 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT Use assert_no_warnings from numpy.testing #27031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
-->
Diff view
30 changes: 3 additions & 27 deletions sklearn/utils/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
assert_array_almost_equal,
assert_array_equal,
assert_array_less,
assert_no_warnings,
)

import sklearn
Expand All @@ -47,7 +48,7 @@
_in_unstable_openblas_configuration,
)
from sklearn.utils._array_api import _check_array_api_dispatch
from sklearn.utils.fixes import VisibleDeprecationWarning, threadpool_info
from sklearn.utils.fixes import threadpool_info
from sklearn.utils.multiclass import check_classification_targets
from sklearn.utils.validation import (
check_array,
Expand All @@ -65,6 +66,7 @@
"assert_approx_equal",
"assert_allclose",
"assert_run_python_script",
"assert_no_warnings",
"SkipTest",
]

Expand All @@ -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 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 43F4 and decorator to ignore warnings.

Expand Down
0