@@ -199,6 +199,7 @@ def apply_dataarray_ufunc(func, *args, **kwargs):
199
199
signature = kwargs .pop ('signature' )
200
200
join = kwargs .pop ('join' , 'inner' )
201
201
exclude_dims = kwargs .pop ('exclude_dims' , _DEFAULT_FROZEN_SET )
202
+ keep_attrs = kwargs .pop ('keep_attrs' , True )
202
203
if kwargs :
203
204
raise TypeError ('apply_dataarray_ufunc() got unexpected keyword '
204
205
'arguments: %s' % list (kwargs ))
@@ -207,7 +208,10 @@ def apply_dataarray_ufunc(func, *args, **kwargs):
207
208
args = deep_align (args , join = join , copy = False , exclude = exclude_dims ,
208
209
raise_on_invalid = False )
209
210
210
- name = result_name (args )
211
+ if keep_attrs and hasattr (args [0 ], 'name' ):
212
+ name = args [0 ].name
213
+ else :
214
+ name = result_name (args )
211
215
result_coords = build_output_coords (args , signature , exclude_dims )
212
216
213
217
data_vars = [getattr (a , 'variable' , a ) for a in args ]
@@ -986,7 +990,8 @@ def earth_mover_distance(first_samples,
986
990
return apply_dataarray_ufunc (variables_ufunc , * args ,
987
991
signature = signature ,
988
992
join = join ,
989
- exclude_dims = exclude_dims )
993
+ exclude_dims = exclude_dims ,
994
+ keep_attrs = keep_attrs )
990
995
elif any (isinstance (a , Variable ) for a in args ):
991
996
return variables_ufunc (* args )
992
997
else :
0 commit comments