-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
ENH: Make assert_almost_equal & assert_array_almost_equal consistent. #7760
Conversation
Will add release note. |
Note that this leads to errors in scipy of the sort
Which is a valid failure, but the previous version let it pass. |
|
||
if not issubdtype(z.dtype, number): | ||
z = z.astype(float_) # handle object arrays | ||
|
||
return around(z, decimal) <= 10.0**(-decimal) | ||
return z < 10**(-decimal) |
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.
If decimal
is a numpy int
, this might start giving zero division errors in the future... 😈
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.
Only after a deprecation period, and of course it would get fixed before the deprecation could land anyway...
e11136d
to
822ef7c
Compare
Hmm, I had a failure for |
Note that this only differs from #6601 in using EDIT: No longer the case. |
822ef7c
to
10b36d4
Compare
Wait, I can do better... |
10b36d4
to
ba2a803
Compare
OK, I think I'm done with this... |
ba2a803
to
3883690
Compare
|
||
if not issubdtype(z.dtype, number): | ||
z = z.astype(float_) # handle object arrays | ||
|
||
return around(z, decimal) <= 10.0**(-decimal) | ||
return z < 1.5 * 10.0**(-decimal) |
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.
Would making this <=
still make sense and remove the possibly stronger tests? Not sure if that makes sense or not. Anyway, looks good to me.
I would like to nudge you towards adding a test ;p. Wondering if we can somehow make it easier to understand what "decimal" means in the documentation. Also "vagaries" seems a bit difficult to me as a non-native speaker, maybe "details"?
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.
I had that, but changed it on account of
nt.assert_almost_equal([1.5], [0], decimal=0)
failing in master due to rounding the difference 1.5 up. Note that
nt.assert_almost_equal([1.49999], [0], decimal=0)
does pass (just to assure everyone the 1.5 is the proper factor).
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.
Can't make everything exactly the same, but I figure that any problems are in tests too close to the edge in any case.
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 need a test. If there had been one in the first place we would never have ended up with 1.5 * 10**(-decimal)
. That was due to the use of a <=
instead of <
, and I think that came about from working around some other perceived bug. I'd just change it if it didn't cause so many new failures in downstream code.
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.
Test added.
This changes the check for scalars in assert_almost_equal so that abs(actual - desired) < 1.5 * 10**(-decimal) Note that the previous documentation claimed that the functions were equivalent to abs(actual - desired) < .5 * 10**(-decimal) but that was not how they behaved in practice. Due to the change in implementation, some very delicate tests may fail that did not fail before. No extra failures were noted in scipy. Closes numpy#5200.
3883690
to
55002a5
Compare
Looks all OK to me. |
This changes the check for scalars in assert_almost_equal so that
Note that the previous documentation claimed that the functions were
equivalent to
but that was not how they behaved as implemented.
Some very delicate tests may fail that did not fail before but no new failures were seen in
SciPy version 0.18.0.dev0+8346eea
.Closes #5200.