-
Notifications
You must be signed in to change notification settings - Fork 285
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
Make weighted aggregation lazy again #5341
Make weighted aggregation lazy again #5341
Conversation
@bouweandela could you test if this solves #5338 for you? |
Thanks for fixing this so quickly @schlunma! Indeed it solves my issue. Regarding the implementation: instead of implementing a custom |
That's great to hear @bouweandela, thanks for testing!
I am not quite sure I understand what you mean here. The aggregators themselves only accept arrays as input, so I am not quite sure why I would convert them to |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## v3.6.x #5341 +/- ##
==========================================
+ Coverage 89.32% 89.37% +0.04%
==========================================
Files 89 89
Lines 22398 22419 +21
Branches 5375 5378 +3
==========================================
+ Hits 20008 20036 +28
+ Misses 1640 1637 -3
+ Partials 750 746 -4
☔ View full report in Codecov by Sentry. |
408c861
to
0937e4f
Compare
408c861
to
e750d94
Compare
Thanks for explaining. I was confused because a _Weights instance is created but then it is not used anymore. For me, it would be easier to understand the code if the class was replaced by a single function. |
Just FYI I've been staring at the code for a few hours now trying to work out what I think the best pattern is. I agree that the use of a class is currently a bit weird, but I haven't settled on an alternative yet. |
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.
Sorry this took so long @schlunma. The underlying code-base made it quite confusing to see what is going on, and even once I had, I found it difficult to come up with suggestions to make it less confusing!
As well as my comments below, this needs a What's New entry.
Thanks for your feedback @trexfeathers, I am currently implementing you suggestions! I noticed that my tests are failing locally now because of #5295. Turns out the fix for that (#5307) is not included in Would it be possible to include #5307 to |
e750d94
to
fb466ba
Compare
@trexfeathers If it helps this use-case cross the line, then it makes sense to me 👍 Technically, #5307 is adding a new feature rather than patching, so it's inclusion is somewhat blurring the lines of the patch/minor release... however, I think that we can defend it's inclusion here. @SciTools/iris-devs Any other core dev opinions on this proposal? |
If you wanted to be strict about the versioning, the other option would be to cut another bonus minor release. The question for me is whether including #5307 is likely to break anyone’s workflow. Since #5295 shows that old version of |
As part of my review I have replicated @schlunma's findings about #5307 on my own machine. I am happy for us to include this PR in a patch release, since it is clearly necessary for a fix.
I'm not especially keen for another bonus minor release. |
One potential problem with the current implementation is that the multiplication by >>> from cf_units import Unit
>>> Unit('kg m-2 s-1') * Unit('1')
Unit('m-2.kg.s-1') Would it make sense to not multiply the units in this case to be strictly backwards-compatible? |
So these two forms are functionally identical, but the second is in the UDUNITS-compliant form. We are hoping to move away from Iris modifying files to make them compliant, so I'm in favour of not multiplying the units if you can make that change. Thanks for spotting |
I agree it would be confusing for users if just summing along a dimension changed their units (particular if an unweighted sum does not change the units, but I have not looked in detail at this change). |
78b3aa5
to
9ccb7d2
Compare
9ccb7d2
to
66ef2aa
Compare
Thanks everyone for your hard work on this! @schlunma @rcomer @bouweandela @bjlittle |
🚀 Pull Request
Description
#5084 broke lazy weighted aggregation by realizing all input arrays. This PR fixes that by
Weights
so it does not subclassnp.ndarray
anymore. Instead, it now provides the attributesarray
andunits
.array
(which is either lazy or non-lazy depending on the input) is then provided asweights
keyword argument._weights_units
when callingAggregator.update_metadata
(which in turn callsunits_func
). Apart from that, the weights units are not used/provide anywhere else.Closes #5338
Consult Iris pull request check list