Repository navigation
Conversation
…n get ignored in some cases.
|
Amazingly, this works without modifications: |
|
What does just |
|
@iguananaut - np.array(q) shouldn't convert to a unitless array in my opinion because the units are uncertain. However, note that it doesn't crash, and even returns sensible results for complicated methods like cumprod because it makes it into an array of quantities: Anyway, I think this should be discussed in the mailing list at this stage. |
|
@iguananaut - subtraction works as expected: |
|
That's not radd and rsub. I mean like: At least in the latter case Numpy rejects it, albeit with a different exception. But as I wrote in the mailing list I think this can be handled in |
|
Also I don't really like the So I don't really see the advantage of removing |
|
@iguananaut - here's what bothers me about keeping Can you see how this could be done? |
|
I also am now against having implicit conversions that drop units, because they simply don't have predictable results to the users - this is another reason why I would prefer to drop array, though I'd also like to make sure that |
|
I'll have to think more about what to do with the warning, but for the other stuff I refer you back to every single point I made last time we talked about this. So far all I see is a desire to remove incredibly useful functionality for the sake a hypothetical problem that I've yet to see. |
|
@iguananaut - so just so I understand your example with: are you saying the exception is wrong and that we should change the exception? If you can find a way to remove that warning, then I agree that there's no harm in keeping the implicit conversion that drops units provided that it does emit a warning in that case. I do agree it's useful functionality as long as the warning is there. What bothers me at the moment is just the presence of the warning in cases where units get added back, and if the only solution is to completely disable the warning, then I would want to disable implicit conversion to unitless objects. Do you see what I mean? |
|
Ultimately, the real problem is that Numpy is buggy and that it shouldn't be calling After all, it doesn't do it for: So maybe the solution is to find a workaround to the Numpy bug rather than trying to selectively disable the warning. What do you think? |
|
Okay, I've spent a little time debugging this to understand exactly what's going on in Numpy's head here. Upon entering a ufunc one of the first things Numpy does is to attempt to create an ndarray from each argument to the function using every way it knows how, including calling that argument's When we remove A little later down it does the check to see if the right-hand argument has an So when we remove So really you're damned either way--if we drop I still feel like there must be a workaround, but I don't have anything specific to give you yet. I still wonder if making Quantity an ndarray subclass isn't still the best option. Now that I have a better understanding how |
|
@iguananaut - thanks for digging deeper into this - this is very helpful! |
…e-instate conversion to Python scalars for dimensionless quantities
|
This still needs a lot of tests to cover the new functionality, but this implements all the functionality in http://mpia.de/~robitaille/astropy/quantity.html |
|
@iguananaut - by the way, the behavior for |
|
@astrofrog - this is a wonderful start. Here, a specific First test: So, something odd happens because the array of Quantities that is formed. This would seem one argument to disallow that from happening. Or perhaps this just requires one to define a "mean" attribute. I'll further comment on astropy-dev. |
There was a problem hiding this comment.
Several of these else: return blocks are redundant. There could just be one: return self.__class__(...) at the end of the method and drop most of the else statements.
|
(I deleted a previous comment I made because I was mistaken) @mhvk - I'm not sure I understand what is wrong in the example you sent. If I use this branch, I get: Similar to what you get. This is correct, right? I mean ideally it would figure out it has to decompose, which you can do manually: but apart from that there's nothing fundamentally wrong with the results, right? |
|
@astrofrog - very weird, I just redid what I had before, and I still get the same I had before, i.e., |
|
@mhvk - I added a test, let's see what Travis says. |
|
@mhvk - bingo, it's Numpy 1.6 that is causing issues. Will look into it locally. |
…ve the wrong units.
|
@mhvk - this should now be fixed - could you try it out with your installation? |
|
@astrofrog - yes, fixed indeed. Great! |
There was a problem hiding this comment.
Not to keep flogging this, but I would also make this a set. Numpy ufuncs should be hashable, so it should work.
There was a problem hiding this comment.
Just out of curiosity, what is the advantage of using a set?
There was a problem hiding this comment.
Every call to __array_wrap__ has to check the calling ufunc for membership in this list. Using a set makes that a roughly O(1) operation.
|
@astrofrog - since it fairly directly affects the pull request, I thought I should repeat a comment also made on astropy-dev: Shouldn't all functions return quantities instead of arrays? This will need to be the case anyway for |
|
@mhvk - that is a good point, and would be easy enough to do. This reminds me I should implement the inverse trigonometric functions! |
|
Numpy is driving me nuts. It turns out that things are made a lot harder by the fact that Numpy can convert Quantity arrays to arrays of Quantities: When one does |
…rse trigonometric functions take dimensionless Quantities and give Quantities in radians.
|
@mhvk @iguananaut - the ufuncs now return dimensionless quantities (where appropriate) and the inverse trigonometric functions now work, so things like @iguananaut - as you'll see, |
|
@astrofrog - it is really nice to see this all working! What I personally still would like is to drop the test for whether scale is unity (this was something you raised on astropy-dev, but didn't get many replies). Since just converting a quantity with a dimension to numbers is no longer possible without both do both work (as does the somewhat nonsensical |
|
If I am understanding correctly, @mhvk's last comment is going back to @astrofrog's question on astropy-dev, right? That is: I'm fairly neutral on this, but I think @mhvk's example demonstrates that we would want this. I can't really think of any cases where this would be ambiguous, and it allows a nice way of doing the log of some unitful quantity: The alternative is to do Aside from that, this looks good to me. @astrofrog, is there pending work here, or is this all currently awaiting comment/endorsement? |
|
@eteq - while the current PR works ok at first glance, it's horribly inefficient, because if you compute e.g. |
|
We decided to go with #929 instead of this, so closing! |
Rather than transform Quantity to a Numpy array sub-class, we actually remove
__array__, which solves the issue first reported in #899:This is actually the safest option, i.e. never implicitly convert to a Numpy array dropping the units.
(I'm preparing an email to astropy-dev about this)