File tree 2 files changed +6
-10
lines changed
2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -433,6 +433,7 @@ def apply_dict_of_variables_vfunc(
433
433
join = "inner" ,
434
434
fill_value = None ,
435
435
on_missing_core_dim : MissingCoreDimOptions = "raise" ,
436
+ keep_attrs = "override" ,
436
437
):
437
438
"""Apply a variable level function over dicts of DataArray, DataArray,
438
439
Variable and ndarray objects.
@@ -445,7 +446,7 @@ def apply_dict_of_variables_vfunc(
445
446
for name , variable_args in zip (names , grouped_by_name ):
446
447
core_dim_present = _check_core_dims (signature , variable_args , name )
447
448
if core_dim_present is True :
448
- result_vars [name ] = func (* variable_args )
449
+ result_vars [name ] = func (* variable_args , keep_attrs = keep_attrs )
449
450
else :
450
451
if on_missing_core_dim == "raise" :
451
452
raise ValueError (core_dim_present )
@@ -522,6 +523,7 @@ def apply_dataset_vfunc(
522
523
join = dataset_join ,
523
524
fill_value = fill_value ,
524
525
on_missing_core_dim = on_missing_core_dim ,
526
+ keep_attrs = keep_attrs ,
525
527
)
526
528
527
529
out : Dataset | tuple [Dataset , ...]
Original file line number Diff line number Diff line change @@ -772,18 +772,13 @@ def test_rolling_exp_keep_attrs(self, ds) -> None:
772
772
# discard attrs
773
773
result = ds .rolling_exp (time = 10 ).mean (keep_attrs = False )
774
774
assert result .attrs == {}
775
- # TODO: from #8114 — this arguably should be empty, but `apply_ufunc` doesn't do
776
- # that at the moment. We should change in `apply_func` rather than
777
- # special-case it here.
778
- #
779
- # assert result.z1.attrs == {}
775
+ assert result .z1 .attrs == {}
780
776
781
777
# test discard attrs using global option
782
778
with set_options (keep_attrs = False ):
783
779
result = ds .rolling_exp (time = 10 ).mean ()
784
780
assert result .attrs == {}
785
- # See above
786
- # assert result.z1.attrs == {}
781
+ assert result .z1 .attrs == {}
787
782
788
783
# keyword takes precedence over global option
789
784
with set_options (keep_attrs = False ):
@@ -794,8 +789,7 @@ def test_rolling_exp_keep_attrs(self, ds) -> None:
794
789
with set_options (keep_attrs = True ):
795
790
result = ds .rolling_exp (time = 10 ).mean (keep_attrs = False )
796
791
assert result .attrs == {}
797
- # See above
798
- # assert result.z1.attrs == {}
792
+ assert result .z1 .attrs == {}
799
793
800
794
with pytest .warns (
801
795
UserWarning ,
You can’t perform that action at this time.
0 commit comments