Skip to content

Aim to raise warnings as errors in test suite #5685

Backlog

Description

@amueller

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.

Activity

  1. giorgiop commented on Nov 2, 2015

    @giorgiop
    Contributor

    +1

  2. amueller commented on Nov 4, 2015

    @amueller
    MemberAuthor

    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.

  3. vighneshbirodkar commented on Dec 10, 2015

    @vighneshbirodkar
    Contributor

    @amueller What about convergence warnings ?

  4. amueller commented on Dec 10, 2015

    @amueller
    MemberAuthor

    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.

  5. TomDLT commented on Dec 12, 2015

    @TomDLT
    Member

    👍

  6. thomasjpfan commented on Jul 5, 2019

    @thomasjpfan
    Member

    This should be resolved given we run pytest with -Werror::DeprecationWarning -Werror::FutureWarning in our CI.

  7. amueller commented on Jul 12, 2019

    @amueller
    MemberAuthor

    @thomasjpfan the point was to raise no warning,s not to raise no deprecation and future warnings.

  8. thomasjpfan commented on Jul 12, 2019

    @thomasjpfan
    Member

    @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.

  9. amueller commented on Jul 12, 2019

    @amueller
    MemberAuthor

    @thomasjpfan the point of the issue was to make the necessary changes and either catch warnings if they are expected or eliminate the cause.

  10. thomasjpfan commented on Jul 12, 2019

    @thomasjpfan
    Member

    @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?

  11. thomasjpfan commented on Jul 12, 2019

    @thomasjpfan
    Member

    We can configure pytest to error on all warnings, which will force us to catch everything.

  12. 3 remaining items

  13. rth commented on Mar 6, 2020

    @rth
    Member

    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) :)

  14. cmarmo commented on Mar 6, 2020

    @cmarmo
    Contributor

    @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?

  15. rth commented on Mar 6, 2020

    @rth
    Member

    I removed the 'help wanted' label. Addressing existing warnings in the test suite would be very useful though.

  16. cmarmo commented on Mar 6, 2020

    @cmarmo
    Contributor

    Addressing existing warnings in the test suite would be very useful though.

    I will try to update their list then. It is worth noticing that they are platform dependent...

  17. cmarmo commented on Mar 6, 2020

    @cmarmo
    Contributor

    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.

  18. amueller commented on Mar 13, 2020

    @amueller
    MemberAuthor

    @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).

  19. cmarmo commented on Mar 13, 2020

    @cmarmo
    Contributor

    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... :)

  20. jnothman commented on Mar 16, 2020

    @jnothman
    Member
  21. cmarmo commented on Sep 7, 2020

    @cmarmo
    Contributor

    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.

  22. ogrisel commented on Sep 8, 2020

    @ogrisel
    Member

    Yes that would be great to fix those warnings but I have not looked in details.

  23. lorentzenchr commented on Nov 15, 2026

    @lorentzenchr
    Member

    We have a CI job with SKLEARN_WARNINGS_AS_ERRORS=1 (see #28372).

    As of ee56c8b (between v1.9.1 and v1.10)

    SKLEARN_WARNINGS_AS_ERRORS=1 pytest
    

    passes

    pytest -Werror
    

    returns

    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.
    
  24. lorentzenchr commented on Nov 25, 2026

    @lorentzenchr
    Member

    With #35476 merged, the warnings turned to errors are no longer hidden away.

    pytest -W error -W "ignore::sklearn.exceptions.SkipTestWarning"
    

    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
    

    TODO:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions