-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
CI Use environment variable to turn warnings into errors in tests and doc build #28372
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
Changes from all commits
a494222
600246d
ac4e4aa
1adc9e1
bd995fc
2fefea7
416678d
d80ab81
be8b69c
5db0b99
0e76426
213e686
35dac82
8d27ed7
20ebe68
fb7fd6f
226c619
0a702f4
1f47260
cefa1ce
b5dad1c
1cbc675
656683f
6502915
11b8a8f
ca0e111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,6 @@ addopts = | |
# source folder. | ||
-p sklearn.tests.random_seed | ||
|
||
filterwarnings = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there was a reason for this anymore ... it seems like the CI agrees. |
||
ignore:the matrix subclass:PendingDeprecationWarning | ||
|
||
[mypy] | ||
ignore_missing_imports = True | ||
allow_redefinition = True | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import unittest | ||
import warnings | ||
from collections.abc import Iterable | ||
from dataclasses import dataclass | ||
from functools import wraps | ||
from inspect import signature | ||
from subprocess import STDOUT, CalledProcessError, TimeoutExpired, check_output | ||
|
@@ -49,7 +50,7 @@ | |
_in_unstable_openblas_configuration, | ||
) | ||
from sklearn.utils._array_api import _check_array_api_dispatch | ||
from sklearn.utils.fixes import parse_version, sp_version | ||
from sklearn.utils.fixes import VisibleDeprecationWarning, parse_version, sp_version | ||
from sklearn.utils.multiclass import check_classification_targets | ||
from sklearn.utils.validation import ( | ||
check_array, | ||
|
@@ -1095,3 +1096,74 @@ def _array_api_for_tests(array_namespace, device): | |
if cupy.cuda.runtime.getDeviceCount() == 0: | ||
raise SkipTest("CuPy test requires cuda, which is not available") | ||
return xp | ||
|
||
|
||
def _get_warnings_filters_info_list(): | ||
@dataclass | ||
class WarningInfo: | ||
action: "warnings._ActionKind" | ||
message: str = "" | ||
category: type[Warning] = Warning | ||
|
||
def to_filterwarning_str(self): | ||
if self.category.__module__ == "builtins": | ||
category = self.category.__name__ | ||
else: | ||
category = f"{self.category.__module__}.{self.category.__name__}" | ||
|
||
return f"{self.action}:{self.message}:{category}" | ||
|
||
return [ | ||
WarningInfo("error", category=DeprecationWarning), | ||
WarningInfo("error", category=FutureWarning), | ||
WarningInfo("error", category=VisibleDeprecationWarning), | ||
# TODO: remove when pyamg > 5.0.1 | ||
# Avoid a deprecation warning due pkg_resources usage in pyamg. | ||
WarningInfo( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add comments (ideally with links to some issue tracker) to motivate the fact that we ignore those particular cases? That might require some git blame archeology. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually add back a comment I removed by mistake, this is about pyamg that uses pkg_resources in its latest release but not in main ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you mean by "in its latest release but not in main". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pyamg 5.0.1 (latest release) will create a DeprecationWarning about using When pyamg > 5.0.1 is released and our minimum pyamg supported version is strictly greater than 5.0.1, we can remove the pkg_resource ignore warning filters. |
||
"ignore", | ||
message="pkg_resources is deprecated as an API", | ||
category=DeprecationWarning, | ||
), | ||
WarningInfo( | ||
"ignore", | ||
message="Deprecated call to `pkg_resources", | ||
category=DeprecationWarning, | ||
), | ||
# pytest-cov issue https://github.com/pytest-dev/pytest-cov/issues/557 not | ||
# fixed although it has been closed. https://github.com/pytest-dev/pytest-cov/pull/623 | ||
# would probably fix it. | ||
WarningInfo( | ||
"ignore", | ||
message=( | ||
"The --rsyncdir command line argument and rsyncdirs config variable are" | ||
" deprecated" | ||
), | ||
category=DeprecationWarning, | ||
), | ||
# XXX: Easiest way to ignore pandas Pyarrow DeprecationWarning in the | ||
# short-term. See https://github.com/pandas-dev/pandas/issues/54466 for | ||
# more details. | ||
WarningInfo( | ||
"ignore", | ||
message=r"\s*Pyarrow will become a required dependency", | ||
category=DeprecationWarning, | ||
), | ||
] | ||
|
||
|
||
def get_pytest_filterwarning_lines(): | ||
warning_filters_info_list = _get_warnings_filters_info_list() | ||
return [ | ||
warning_info.to_filterwarning_str() | ||
for warning_info in warning_filters_info_list | ||
] | ||
|
||
|
||
def turn_warnings_into_errors(): | ||
warnings_filters_info_list = _get_warnings_filters_info_list() | ||
for warning_info in warnings_filters_info_list: | ||
warnings.filterwarnings( | ||
warning_info.action, | ||
message=warning_info.message, | ||
category=warning_info.category, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move the whole "Environment variables" section of the doc to its own
environment_variables.rst
file instead ofparallelism.rst
but ok for not doing it as part of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree ...