-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Absolute tolerance in approximate equality tests #10562
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
Comments
It's sneaky that there's a difference between assert_allclose and assert
np.allclose too :\
This sounds reasonable, but as usual a PR would help make it clear!
|
Not sure it is 100% relevant to this issue but we are using |
I don't think we benefit from changing everything to assert_allclose, and we would run the risk of finding that tests fail on some platforms etc., although we can recommend it for new tests. I'm still somewhat undecided about @rth's proposal here. |
#10280 (comment) is also a good point by @jnothman
yes, I think it would be useful to at least have some recommendations in contributors docs of what to use for new tests. BTW for the record, |
I'm a little surprised to find that pytest.approx automatically knows how
to compare arrays.
|
Not arrays, just floats. |
I could reproduce this issue on master:
my HEAD is at eed8379
These tests keep on failing despite a rebuild. I just cloned, fetched the pip dependencies, and then executed |
do you want to tag as help wanted or just do it yourself? |
Thanks for mentioning it @gamazeps !
Will make a PR to fix issues discussed in #9485 (comment) and #10561, as for the rest of this PR it doesn't seem there is clear consensus on what should be done (e.g. #10562 (comment)) |
Closing as "potentially problematic, but no consensus on actions needed". |
In a number of places in tests,
numpy.testing.assert_allclose
is used with default absolute tolerance parameter which isatol=0
.This means in particular that
np.testing.assert_allclose(0, 1e-16)
will fail. More context for the reasons behind this choice can be found in numpy/numpy#3183 (comment) and PEP485, which can be summed up with,The issue is that occasionally, the tests will pass, and but then may fail on some other platform.
For instance, this test in
estimator_checks.py
passes CI on master, but then randomly fail for osx: [1], [2] correspond to the same commit, one for the PR, one in the forked repo (this test fails with the bellow message and not necessary for the same Python versions) ,test_gradient_boosting_loss_functions.py
compares floats to 0 withatol=0
but doesn't fail.When
atol
is used, it not very consistent.As to
sklearn.utils.testing.assert_allclose_dense_sparse
it has by defaultatol=1e-9
and not 0.While the necessary absolute tolerance is test dependent, it might still be useful to
DEFAULT_ATOL
insklearn.utils.testing
) , except for the cases when it has to be increased for specific reasons.atol
when it's definitely reasonable to do so (e.g. in probability equalities)sklearn.utils.testing.assert_allclose_dense_sparse
andsklearn.utils.testing.assert_allclose
have the same defaultatol
.This might help improving the numerical stability of tests and prevent some of the tests failures on less common platforms cc @yarikoptic
What do you think?
The text was updated successfully, but these errors were encountered: