-
Notifications
You must be signed in to change notification settings - Fork 416
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
Updates to pint/xarray master branch (and xarray v0.13) compatability #1144
Conversation
This looks like a great amount of work cleaning that up. It makes sense to convert all those calls that we expect to drop units to just drop the units--though I long for the day where we largely don't care. I'm surprised so many tests needed any update to precision, though I guess that makes sense with the constants changes? Looks like this conflicts with another update for xarray testing. |
Just for my own sake of understanding the roadmap, would this be something that can be done for v1.0, assuming there are compatible xarray and pint releases with
Comparing versions, I think only G and R were the base constants that changed, but since there are quite a few derived constants from R, I'm not surprised at how many calculations were affected. Here's a diff of the values of the constants. While most of the changes in the tests seemed roughly in proportion to the changes in the constants, the parcel-related calculations caught me a little bit by surprise. But, digging into it a little bit, I suspect that Lines 260 to 267 in 67547dc
(which is then integrated upward/downward using
Once I get the numpy dtype issue figured out, I'll be sure to rebase and fix that merge conflict (hopefully after #1142 makes it in). |
It's a possibility for 1.0. It's going to come down to looking at the tradeoffs, including whether we think we'll need to make any interface changes. My goal is to not be doing backwards-incompatible stuff for awhile after 1.0. |
I finally got the chance to get back to this and come up with what I hope is a reasonable solution to the dtype issue that works with Python 2.7 and Windows. Assuming the required CI builds pass, all that should be left to fix on this PR (for the pint/xarray master branch build) are the broken tests for geopotential <-> height conversion. Should MetPy fix its own value for |
Another round of fixes, and another round of new test failures...
I'm not sure what's going on with the skew T and station plot failures though. |
When I tried to replicate the skew T and station plot failures locally, they seemed like very minor differences. Should the tolerances be increased, or am I missing some important difference? Also, I saw that xarray v0.13.0 was just released, so the "pint Quantity mistakenly inside a DataArray" bug corrected here may start showing up soon elsewhere. |
Can confirm that CI is no longer passing due to the xarray update, so it would be nice to get this in soon. The SkewT image mismatch is surprising to me too. |
There were *many* places in the code base where passing pint Quantities to numpy functions was assumed to return a plain ndarray. This behavior will no longer be the case after pint implements __array_function__ in its next version, and so, this modifies usage to explicitly request magnitude where it is assumed that quantities are stripped. Also, makes some miscelaneous changes with regards to the split between scalar and sequence quantity classes. Updates test tolerances to account for changes to base constants from pint v0.9 defaults to v0.10 defaults (except for geopotential <-> height conversions which are problematic and resolved elsewhere). Finally, resolves issues with xarray v0.13.0 (no implicit casting to ndarray or inplace argument anymore).
I was able to get the xarray fixes in the docs added to this, so de54647 in #1160 can be removed. With that error in mind, I changed the added allowed failure build from one that just ran the test suite to two, one for coverage and one for docs, to hopefully not miss similar docs-only issues. Also, after digging into the geopotential <-> height conversions some more in an attempt to reimplement them using standard gravity instead of the gravitational constant as discussed in the telecon, I realized it would fundamentally change the assumptions of those calculations, and change the results much more than pint's change in |
That seems reasonable. I'll merge as soon as the last Travis build passes. Thanks for opening the other issue. |
@dopplershift In the process of writing up that issue I originally mentioned, I managed to work my way through the main concerns I had, so I just put in a PR (#1174) that changes the formulas to use standard gravity, but with commentary on how it changes the assumptions involved in the calculation. Discussion on that change is certainly welcome! |
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.
Looks good. Kinda scary how many places needed adjustment, though.
Description Of Changes
There were many places in the code base where passing pint Quantities to numpy functions was assumed to return a plain ndarray. This behavior will no longer necessarily be the case after pint implements
__array_function__
in a future version, and so, this modifies usage to explicitly request magnitude where it is assumed that quantities are stripped. Also, makes some miscellaneous changes with regards to the split between scalar and sequence quantity classes. (xref #1111)Similarly, there was one place where the xarray accessor assumed that a pint Quantity being inserted into a DataArray would cast to a plain ndarray. This will no longer be the case with xarray's next release and the implementation of
__array_function__
in pint.Also, makes updates to test tolerances to account for changes to base constants from pint v0.9 defaults to v0.10 defaults (except for geopotential <-> height conversions which are rather sensitive to the value of G). (xref #1115 (comment))
Finally, adds a dev build to Travis configuration that builds xarray and pint from their respective master branches on git.
Overall, based on tests locally, this should resolve all the new issues created by using xarray from its master branch and pint from andrewgsavage/pint#6 except for the following:
axvline
/axhline
tests, in which matplotlib tries to compare the supplied pint Quantity to a plain float, which pint does not allowChecklist
EDIT: After looking through the CI builds, I realized that my current workaround for the numpy type casting (to fixbound.dtype
being unavailable) isn't very robust. I'll need to find a better way of doing that.