-
Notifications
You must be signed in to change notification settings - Fork 473
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
Fix unit tests errors with numpy >=1.13 (Fix 577) #630
Conversation
Test pint in travis against the latest numpy (currently 1.14.x)
In nummpy >1.11, the a**=b raises an exception if a and b are quantities and a.magnitude is a ndarray. Fix this case
pint.testsuite.test_umath.TestFloatingUfuncs.test_isfinite uses np.isreal instead of np.isfinite. This is probably a copy-paste error. Fix it
np.isreal(v) is implemented (at least in np >=1.13) as a check that v.imag != 0 . Since Quantity reimplements imag to return units (see issue hgrecco#171) , np.isreal always returns False for any quantity. Therefore, this test is marked as expected to fail for now (note that the tests with np <1.13 will now yield an unexpected success).
Add a test that checks various cases of comparing a quantity to (non-quantity) zero. Comparisons against zero should work even for non-dimensionless quantities, and non-multiplicative quantities should be properly supported.
Implement the following special behaviour when comparing a quantity against zero: a) comparing against (non-quantity) zero is allowed for any quantity b) comparing against zero-magnitude quantities of incompatible dimensionality raises a Dimensionality error, except for the case of equality, for which it always returns False Notes: 1.- Numpy arrays of zeros are also supported and the comparison rules apply elementwise 2.- In the case of non-multiplicative units, the rules above apply after converting to base units if the autoconvert offset flag is set. Otherwise they raise an OffsetUnitCalculusError.
This reverts commit fcbceaef41b278fd57c7bab7dc901f35de8c154d.
bors try |
🔒 Permission denied Existing reviewers: click here to make cpascual a reviewer |
It seems that @hgrecco should give me permissions in bors beforeI can try... I got this email:
|
Great work. Go ahead and try to merge it (I could do it but I want to try again the Bors workflow, I have given you access). |
bors try |
tryBuild succeeded |
I attempted to do a So now I am going to attempt the |
bors r+ |
630: Fix unit tests errors with numpy >=1.13 (Fix 577) r=cpascual a=cpascual This PR fixes the 4 test errors/failiures reported in #577 and adds new travis builds with numpy 1.14 3 of the 4 problems are relatively trivial to solve. The remaining one (`test_isreal`) is not so trivial because it involves allowing to compare a *non-dimensionless* quantity against zero. The reason is that `numpy.isreal(x)` essentially does `x.imag !=0` if the `imag` method is implemented in x... and since Quantity reimplements .imag to return units (see #171), the check always returns False if x is a non-dimensionless quantity. As mentioned, this can be solved by allowing comparisons against zero. Actually, this has already been requested in #194, but it was not implemented. In this PR, I implemented the comparison-to-zero feature and provide several new unit tests for it. AFAIK this implementation takes into account the concerns expressed by @hgrecco in #194. But if the feature is not wanted, we can just revert the last 3 commits of this PR and then `test_isreal` will left with an expected failure flag. The rules that I implemented for the comparison-with-zero are: ``` a) comparing against (non-quantity) zero is allowed for any quantity b) comparing against zero-magnitude quantities of incompatible dimensionality raises a Dimensionality error, except for the case of equality, for which it always returns False Notes: 1.- Numpy arrays of zeros are also supported and the comparison rules apply elementwise 2.- In the case of non-multiplicative units, the rules above apply after converting to base units if the autoconvert offset flag is set. Otherwise they raise an OffsetUnitCalculusError. ``` Fixes #577 Co-authored-by: Carlos Pascual <cpascual@cells.es>
Build succeeded |
Since this was an experiment on usin bors, here are some observations:
In the bors docs it says:
I think that this can be fixed by adding the following blacklist to travis.yml (I submitted PR #631 to test it)
|
631: prevent Travis from building bors tmp branches r=cpascual a=cpascual As noticed in #630 (comment) , Travis should not build the staging.tmp and trying.tmp branches used internally by bors. So blocklist them in travis.yml Co-authored-by: Carlos Pascual <cpascual@cells.es>
This PR fixes the 4 test errors/failiures reported in #577 and adds new travis builds with numpy 1.14
3 of the 4 problems are relatively trivial to solve.
The remaining one (
test_isreal
) is not so trivial because it involves allowing to compare a non-dimensionless quantity against zero. The reason is thatnumpy.isreal(x)
essentially doesx.imag !=0
if theimag
method is implemented in x... and since Quantity reimplements .imag to return units (see #171), the check always returns False if x is a non-dimensionless quantity.As mentioned, this can be solved by allowing comparisons against zero. Actually, this has already been requested in #194, but it was not implemented.
In this PR, I implemented the comparison-to-zero feature and provide several new unit tests for it. AFAIK this implementation takes into account the concerns expressed by @hgrecco in #194. But if the feature is not wanted, we can just revert the last 3 commits of this PR and then
test_isreal
will left with an expected failure flag.The rules that I implemented for the comparison-with-zero are:
Fixes #577