Fix type error for Coarsen reduction methods - #11556
Open
andrew-s28 wants to merge 3 commits into
Open
Conversation
Contributor
|
That's a nice improvement! Can you fix the mypy errors please? We ccould explore move these to https://github.com/pydata/xarray/blob/main/xarray/util/generate_aggregations.py but I think part of the issue is how some of these aggregations are written in terms of others. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The methods for the documented reduction operations on
Dataset.coarsen()andDataArray.coarsen()were dynamically generated via injected methods that relied on code in several different modules. The dynamic generation of these methods also meant that type errors were raised when trying to access reduction methods, e.g., the following code example.Minimal working example
This PR moves all the logic for
Coarsenintoxarray.computation.rollingand attempts to mirror the implementation ofxarray.computation.rolling.Rolling. It should result in no functional changes as far as I can tell and should make future maintenance slightly easier (not having to track the injection across files).Checklist
whats-new.rstPS: I think the
xarray.computation.rollingmodule might be due for a refactoring and don't seem to have been touched a lot in recent years. There's also #8059 related to this module, which I didn't address here to keep the scope limited. Happy to discuss a larger refactoring effort if there's any interest 😄