-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
DataArrayCoarsen.reduce passes kwargs to coordinate function #8059
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
Thanks for reporting this. Any ideas for the best way to resolve it with a PR? An extra Related to #7981 in that subtleties with the whole |
I think we should encourage the use of |
I was about to post something similar, so 👍 from me (though there are a few more options other than |
I don't really have much knowledge on what practices are preferred in xarray API and implementation, but I would have added the kwargs for the |
exactly. We're proposing something like this: from functools import partial
def coords_reduce(x, axis, arg1):
...
da.coarsen({"x": 2, "y": 2}, coord_func=partial(coords_reduce, arg1="additional data").reduce(
reduce_func_with_kwargs, dummy=1
) and then obviously That aside, though, it does feel a bit odd that we're passing |
What is your issue?
When using custom reducing function with the
.reduce(func, keep_attrs=None, **kwargs)
method ofxarray.core.rolling.DataArrayCoarsen
object, keyword arguments of the reduce method are passed to the given reducing function (func
) as documented. However, if a different function is given to reduce the coordinates when the coarsen or rolling object is created, e.g.coord_func="mean"
, the same kwargs get also passed to the coordinate reducing function. This is quite often undesired, as the function to reduce the coordinates might not have the same kwargs as the function used to reduce the actual data.Here is an example:
The first reduction works as expected, as no kwargs are passed to the reduce method. However, the latter reduction raises a TypeError
This is because kwarg
dummy=1
gets passed to coordinate reduction function"mean"
(nanmean
) in addition toreduce_func_with_kwargs
inxarray/core/rolling.py:1012
.Currently, it is undocumented that the kwargs are also passed to the coordinate reduction function, so this is probably technically not a bug. However, I think in many cases you might want to use different kwargs for the functions and some solution for this case would be nice.
Cheers,
Sasu Karttunen
The text was updated successfully, but these errors were encountered: