-
Notifications
You must be signed in to change notification settings - Fork 475
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
real
and imag
attributes of Quantities do not preserve units
#171
Labels
Comments
Good idea. We will implement this for the next bugfix release. |
I am deferring the implementation of |
cpascual
pushed a commit
to cpascual/pint
that referenced
this issue
Apr 13, 2018
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).
bors bot
added a commit
that referenced
this issue
Apr 13, 2018
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>
znicholls
pushed a commit
to znicholls/pint
that referenced
this issue
Aug 29, 2018
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).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is perhaps a feature request. Currently, if you create a complex Quantity and take its real or imaginary part using the
real
orimag
attributes, the magnitude is returned, but the units are lost.Presumably this is not yet implemented because
real
andimag
are in the unique position of being attributes of ndarrays, rather than methods, which are currently dealt with via__copy_units
and friends.Looking through numpy's docs, there appear to be very few attributes should have units, so the implementation should not be too bad. The only ones I see are
real
,imag
,T
, and maybeflat
.The text was updated successfully, but these errors were encountered: