-
-
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
Move .rolling_exp
functions from reduce
to apply_ufunc
#8114
Conversation
cd9c085
to
c12632b
Compare
After #8183, that's pretty nice now! I think we could start to move some of these over. There is one failing test, but that seems like the test is testing for something |
c12632b
to
5ea724b
Compare
Could anyone who has context or views on
Otherwise I think we remove the test and fall back to the |
I want to see this fixed but ok to drop the test for now. |
Great, thanks @mathause — done |
@max-sixty @mathause FYI, to implement
|
Nice! Added... |
reduce
to apply_ufunc
.rolling_exp
functions from reduce
to apply_ufunc
But actually I'm not seeing it working — have I made a mistake? Otherwise I can revert that commit and we can split into a separate PR |
xarray/core/computation.py
Outdated
@@ -445,7 +446,7 @@ def apply_dict_of_variables_vfunc( | |||
for name, variable_args in zip(names, grouped_by_name): | |||
core_dim_present = _check_core_dims(signature, variable_args, name) | |||
if core_dim_present is True: | |||
result_vars[name] = func(*variable_args) | |||
result_vars[name] = func(*variable_args, keep_attrs=keep_attrs) |
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.
I think that can be any function and there is no guarantee that it will consume this argument (admittedly I am surprised why this does not error in our test suite - so I may be wrong). Also isn't this on the DataArray
level while the missing attrs are on the Dataset
level?
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.
Yes, good chance that we are undertesting here. But the error is raised for the attribute on z1
(DataArray
level). And this propagates keep_attrs
.
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.
OK this only works for core_dim_present
@max-sixty, so the attributes would also have to be removed on on_missing_core_dim == "copy"
. But as @mathause already mentioned, it's debatable if it should loose it's attrs.
Hmm, yes probably good to revert and handle in another PR. I'll check again locally, good chance I've messed up my branch. |
@kmuehlbauer & @max-sixty Sorry - I was wrong (one shouldn't try to figure these things out on the phone display...). I think the issue is that the attrs are not dropped when a DataArray is copied (so pretty much the exact opposite of what I thought before 😂). Here is a small repro: import xarray as xr
air = xr.tutorial.open_dataset("air_temperature")
air["a"] = 1
air.a.attrs = {"key": "value"}
xr.apply_ufunc(
lambda x: x.mean(axis=-1),
air,
input_core_dims=[["time"]],
keep_attrs=False,
on_missing_core_dim="copy"
).a
|
This reverts commit d27bff4.
OK, I reverted the suggested changes. Unless there's strong disagreement, let's make the more general changes to |
rolling_exp
loses coords #6870whats-new.rst
A similar change should solve #6528, but let's get one finished first...
Posting for discussion, will comment inlineReady for merge