-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: Make allclose(x, y) equivalent to all(x == y) when both x and y are... #4108
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
Conversation
…are exact. This improves performance and makes allclose() work on non-numeric dtypes. Closes numpygh-4107.
There is a little awkward thing. For fun large fun integer values (or if large values are given to the allowed difference), the behaviour would change. That should be fine, but the change needs to be documented in the function and release notes. Also, you need to channel objects through these, too; maybe it would be better as a negative list rather than a postive one. |
xinf = isinf(x) | ||
yinf = isinf(y) | ||
xexact = x.dtype.kind not in 'fc' | ||
yexact = y.dtype.kind not in 'fc' |
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.
The behavior for integers should not be changed.
They should also be compared respecting the tolerances given, not requiring exact equality.
I think the correct fix is to make |
My use-case is that of record arrays. With the patch, I get
without the patch, this produces an error. I agree that the behavior for ints should not change. Maybe just change the test to |
I am +/-0 on integer types, and OK with strings being passed through. But your example makes me more cautious. What if the record array has an inexact field? If it is possible to have an inexact number not being matched within tolerance with the function, I prefer to not change it. |
@seberg - here is what I see with the patch:
This is what I want: numeric fields compared with tolerance and non-numeric ones compared exactly. |
@abalkin, that is because 5+1e-10 is 5 for floats, use doubles :) ( |
My bad. It looks like record arrays need to be special cased. Let's take this in steps:
On #3, I think we need to preserve the following behavior:
|
... exact.
This improves performance and makes allclose() work on non-numeric dtypes.
Closes gh-4107.