Repository navigation
Quantities should always allow comparison with zero - #1254
Conversation
|
This sounds reasonable to me, though I'm not sure--could definitely use further discussion. |
|
Yeah -- seems reasonable. We've deliberately excluded offset units (such as Celcius and Fahrenheit would require to convert to Kelvin), so this assertion should hold true. What's the use case, however? Why not just require the slightly more pedantic case of putting a unit on 0, which gives the added benefit of checking that the unit is compatible? |
|
@mdboom - the use case was that I was trying to make some more numpy functions work, and realised that |
|
Still feel this is sensible, but no hurry. |
|
Since this isn't a priority for 0.3, I'm reassigning to 0.4. |
|
After implementing support for since the units are irrelevant. |
|
@astrofrog - I still had my "zero can have arbitrary units" PR around, so now updated it to include |
|
@astrofrog - no hurry, but if you have time to look at this comparison-with-zero/inf PR, that would be great. |
|
Will do later today hopefully, and @mdboom should look too. |
There was a problem hiding this comment.
It might make more sense to include np.all here, rather than place the burden on the callers of this function.
Also, maybe add a docstring. (I know it's private, but it might not be clear what its purpose is a few months from now).
|
Looks good, aside from my minor comments. |
|
@mdboom - thanks, all comments implemented. |
There was a problem hiding this comment.
Zero has become special with this PR: previously, the assertion was correct since c.x[0], which has units of kpc, is not equal to 0, which does not have these units. However, with the present PR, 0 can have any units, and thus one does have c.x[0] == 0
(I must admit that I'm not 100% sure that the above was the intent of the test...)
|
@astrofrog, @mdboom - looking over old branches, I encountered this one. I think I had all your comments addressed, so it should be good to go. (I rebased on current master to make it mergeable, so travis will run once more as well.) |
Quantities should always allow comparison with zero
|
If this is merged shouldn't it be 0.3? |
|
Yes, 0.3. |
Also while working on #929 (where I needed to intercept a
where(q==0,...), I noticed that comparisons of the formq==0,q>0raise an exception unlessqis dimensionless. They probably shouldn't as this has a well-defined answer (as 0 can have any unit it wants!). Since quantity is so much in flux right now, I won't do a PR, but just note that one way of simplifying this is by defining a difference function which returns a plain array for testing in the various comparisons. E.g., things can be made to work with.(the
raise_on_incompatible=Falseoption is there for==, which should simply returnFalsein this case).