You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Aim to raise warnings as errors in test suite #5685
Going through the fun of seeing all the deprecated usages of numpy in master and 0.17, I think it would be nice to let nose break on warnings.
I don't think there should be any warnings when running the tests, and that would put the effort much more on the contributors, instead of the maintainers.
It would also be nice to check warnings in the examples. We use deprecated things from matplotlib, and we should fix them when they are deprecated, not when they break.
if we expect them, we should catch them. But I feel like there shouldn't be convergence warnings on toy datasets. If we decreased the number of iterations to speed up tests, it's fine to catch them.
@amueller pytest's -Werror::DeprecationWarning -Werror::FutureWarning converts the warnings into errors. When scipy or numpy deprecates something our CI is raising an error. This happens from time to time in our nightly CI which uses the master versions of numpy and scipy.
Edit: Converting warnings to errors forces us to make changes.
@amueller Since we are already catching DeprecationWarning and FutureWarning, is this issue focused on all our custom warnings defined in sklearn/exceptions.py, such as ConvergenceWarning?
I have add a CHECK_ALL_WARNINGS variable to the Azure build scripts and the result is here.
To be more specific, adding an env variable to azure as long as it doesn't change pytest config files could be OK. Anyway we wouldn't be able to enable it as long as all warning are addressed which is a lot of work (and sometimes non trivial #11536) :)
@rth, thanks for your answer. I wasn't aware of previous discussions, sorry. Anyway, adding the variable didn't take so much time and my PR is just a fake one on my fork.
Is it worth it to keep this issue open and labelled 'help wanted', then?
First list (the easier one) at #16651.
I'm wondering if the check on warnings couldn't be added for those pipelines that don't fail right now: this will prevent new warnings to be added at least for them.
@cmarmo I think the main concern that @rth (and others?) raised was that a warning can be introduced by a change in an upstream library like numpy and making the tests fail based on upstream changes can be confusing. I'm not entirely sure what the best way forward is, though addressing existing warnings is certainly useful (I've found many bugs that way over the years).
Thanks @amueller, this is clear to me. I'm trying to identify warnings in the builds and understand if they are solvable or not. I'm not planning to solve all the warnings, and this is very useful for me to learn about pytest. Anyway, there is at least one warning linked to pytest marks that we can fix (#16652)... if you want to take a look and review it... :)
There is a bunch of numpy DeprecationWarning in the test suite (see for example the build of this fake PR)
E numpy.VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
Are those warnings worth to fix? If yes I will make a checklist and open a new issue for them. @rth? Thanks.
ERROR sklearn/cluster/tests/test_hierarchical.py - pytest.PytestUnknownMarkWarning: Unknown pytest.mark.no_check_spmatrix - is this a typo? You can register custom ...
ERROR sklearn/cluster/tests/test_spectral.py - pytest.PytestUnknownMarkWarning: Unknown pytest.mark.no_check_spmatrix - is this a typo? You can register custom ...
ERROR sklearn/linear_model/tests/test_sgd.py - pytest.PytestUnknownMarkWarning: Unknown pytest.mark.no_check_spmatrix - is this a typo? You can register custom ...
ERROR sklearn/tests/test_common.py - pytest.PytestUnknownMarkWarning: Unknown pytest.mark.no_check_spmatrix - is this a typo? You can register custom ...
ERROR sklearn/tests/test_docstrings.py - pytest.PytestUnknownMarkWarning: Unknown pytest.mark.no_check_spmatrix - is this a typo? You can register custom ...
ERROR sklearn/tests/test_metaestimators.py - sklearn.exceptions.SkipTestWarning: Can't instantiate estimator FrozenEstimator
ERROR sklearn/utils/tests/test_estimator_checks.py - pytest.PytestUnknownMarkWarning: Unknown pytest.mark.no_check_spmatrix - is this a typo? You can register custom ...
ERROR sklearn/utils/tests/test_typedefs.py - pytest.PytestCollectionWarning: cannot collect 'testing_isnan' because it is not a function.
results in 1460 failed, 39792 passed, 15168 skipped, 186 xfailed, 98 xpassed in 1424.85s (0:23:44)
The good news is that with this PR we can see those warnings as errors if we want to.
Examples
FAILED sklearn/cluster/tests/test_affinity_propagation.py::test_affinity_propagation_equal_points - UserWarning: All samples have mutually equal similarities. Returning arbitrary cluster center(s).
FAILED sklearn/decomposition/tests/test_nmf.py::test_nmf_smoke[cd-tall-nndsvd] - sklearn.exceptions.ConvergenceWarning: Maximum number of iterations 200 reached. Increase it to improve convergence.
FAILED sklearn/model_selection/tests/test_validation.py::test_cross_val_predict_unbalanced - UserWarning: The least populated class in y has only 1 members, which is less than n_splits=2.
FAILED sklearn/tree/tests/test_tree.py::test_sparse_input[sparse-mix-ExtraTreeClassifier] - RuntimeWarning: divide by zero encountered in log
FAILED sklearn/tree/tests/test_tree.py::test_empty_leaf_infinite_threshold[None] - RuntimeWarning: overflow encountered in cast
FAILED sklearn/utils/tests/test_testing.py::test_sklearn_warnings_as_errors[warning_info13] - DeprecationWarning: vert. bool was deprecated in Matplotlib
Activity
giorgiop commentedon Nov 2, 2015
+1
amueller commentedon Nov 4, 2015
It would also be nice to check warnings in the examples. We use deprecated things from matplotlib, and we should fix them when they are deprecated, not when they break.
vighneshbirodkar commentedon Dec 10, 2015
@amueller What about convergence warnings ?
amueller commentedon Dec 10, 2015
if we expect them, we should catch them. But I feel like there shouldn't be convergence warnings on toy datasets. If we decreased the number of iterations to speed up tests, it's fine to catch them.
TomDLT commentedon Dec 12, 2015
👍
thomasjpfan commentedon Jul 5, 2019
This should be resolved given we run
pytestwith-Werror::DeprecationWarning -Werror::FutureWarningin our CI.amueller commentedon Jul 12, 2019
@thomasjpfan the point was to raise no warning,s not to raise no deprecation and future warnings.
thomasjpfan commentedon Jul 12, 2019
@amueller pytest's
-Werror::DeprecationWarning -Werror::FutureWarningconverts the warnings into errors. When scipy or numpy deprecates something our CI is raising an error. This happens from time to time in our nightly CI which uses the master versions of numpy and scipy.Edit: Converting warnings to errors forces us to make changes.
amueller commentedon Jul 12, 2019
@thomasjpfan the point of the issue was to make the necessary changes and either catch warnings if they are expected or eliminate the cause.
thomasjpfan commentedon Jul 12, 2019
@amueller Since we are already catching
DeprecationWarningandFutureWarning, is this issue focused on all our custom warnings defined insklearn/exceptions.py, such asConvergenceWarning?thomasjpfan commentedon Jul 12, 2019
We can configure pytest to error on all warnings, which will force us to catch everything.
3 remaining items
rth commentedon Mar 6, 2020
To be more specific, adding an env variable to azure as long as it doesn't change pytest config files could be OK. Anyway we wouldn't be able to enable it as long as all warning are addressed which is a lot of work (and sometimes non trivial #11536) :)
cmarmo commentedon Mar 6, 2020
@rth, thanks for your answer. I wasn't aware of previous discussions, sorry. Anyway, adding the variable didn't take so much time and my PR is just a fake one on my fork.
Is it worth it to keep this issue open and labelled 'help wanted', then?
rth commentedon Mar 6, 2020
I removed the 'help wanted' label. Addressing existing warnings in the test suite would be very useful though.
cmarmo commentedon Mar 6, 2020
I will try to update their list then. It is worth noticing that they are platform dependent...
cmarmo commentedon Mar 6, 2020
First list (the easier one) at #16651.
I'm wondering if the check on warnings couldn't be added for those pipelines that don't fail right now: this will prevent new warnings to be added at least for them.
amueller commentedon Mar 13, 2020
@cmarmo I think the main concern that @rth (and others?) raised was that a warning can be introduced by a change in an upstream library like numpy and making the tests fail based on upstream changes can be confusing. I'm not entirely sure what the best way forward is, though addressing existing warnings is certainly useful (I've found many bugs that way over the years).
cmarmo commentedon Mar 13, 2020
Thanks @amueller, this is clear to me. I'm trying to identify warnings in the builds and understand if they are solvable or not. I'm not planning to solve all the warnings, and this is very useful for me to learn about pytest. Anyway, there is at least one warning linked to pytest marks that we can fix (#16652)... if you want to take a look and review it... :)
jnothman commentedon Mar 16, 2020
cmarmo commentedon Sep 7, 2020
There is a bunch of numpy DeprecationWarning in the test suite (see for example the build of this fake PR)
Are those warnings worth to fix? If yes I will make a checklist and open a new issue for them. @rth? Thanks.
ogrisel commentedon Sep 8, 2020
Yes that would be great to fix those warnings but I have not looked in details.
lorentzenchr commentedon Nov 15, 2026
We have a CI job with
SKLEARN_WARNINGS_AS_ERRORS=1(see #28372).As of ee56c8b (between v1.9.1 and v1.10)
passes
returns
lorentzenchr commentedon Nov 25, 2026
With #35476 merged, the warnings turned to errors are no longer hidden away.
results in 1460 failed, 39792 passed, 15168 skipped, 186 xfailed, 98 xpassed in 1424.85s (0:23:44)
The good news is that with this PR we can see those warnings as errors if we want to.
Examples
TODO:
sklearn._losssklearn.callbacksklearn.clusterTST fix all warnings in tests ofsklearn.cluster#35520sklearn.composesklearn.covarianceFIX MinCovDet: no spurious "Determinant has increased" warning #35531sklearn.cross_decompositionsklearn.datasetssklearn.decompositionsklearn.ensemblesklearn.experimentalsklearn.externalssklearn.feature_extractionsklearn.feature_selectionsklearn.frozensklearn.gaussian_processsklearn.imputesklearn.inspectionsklearn.linear_modelTST fix all warnings in tests ofsklearn.linear_model#35516sklearn.manifoldsklearn.metricssklearn.mixturesklearn.model_selectionsklearn.neighborssklearn.neural_networksklearn.preprocessingsklearn.semi_supervisedsklearn.svmsklearn.testssklearn.treesklearn.utils