-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Optionally treat NaNs as equal to each other in isapprox #19936
Comments
This also affects |
Make sense to me.
|
I guess we should really do this in this release since we're deprecating |
What should we call this keyword? |
I guess |
That was my intent. Also nanseq, reads like "nan sequence", so |
I have prepared candidate changes, if you would like to take a look: |
A PR would be lovely! |
* add `nans` keyword to isapprox * test isapprox with nans * fix typo * isapprox with `nans` keyword * isapprox with `nans` keyword * add tests for isapprox([nan],[nan]) * fix bad name * move isapprox tests into floatapprox.jl * issue #19936 * fixes trailing whitespace? * quash whitespace error * isapprox description readability * change isapprox nan test short-circuiting * remove trailing whitespace * vanquish trailing whitespace
Thanks @JeffreySarnoff ! |
@test_approx_eq
has been deprecated by #19880, now the suggested way to compare numbers is@test isapprox(a ,b)
(or some other fancy Unicode syntax). However,@test_approx_eq
had a feature thatisapprox
is missing:@test_approx_eq NaN NaN
didn't error. When performing tests, it makes sense to treatNaN
s as equal (i.e., whatisequal
does): even ifisnan
is available, havingisapprox
dealing nicely withNaN
s may be useful for cases likeisapprox([1, NaN, Inf], [1, NaN, Inf])
, where there is a mixture of numbers and not-numbers.My suggestion: optionally have
isapprox
treatNaN
values as equal to each other (maybe only in tests).A bit of background: in a package of mines I have a test where I was using
@test_approx_eq
, relying on the fact that it treatedNaN
s as equal. When I moved to@test
+isapprox
I had to define a new method for a custom type in the testing suite and now I'm fine. With this ticket my aim is not to advocate for this feature, because I currently don't need it, but to suggest a possible improvement toisapprox
that may be useful above all for testing.The text was updated successfully, but these errors were encountered: