Skip to content

Commit 71a6b1c

Browse files
committed
shoyer's solution
1 parent 27ed788 commit 71a6b1c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

xarray/core/common.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -856,11 +856,7 @@ def where(self, cond, other=dtypes.NA, drop=False):
856856
self = self.isel(**indexers)
857857
cond = cond.isel(**indexers)
858858

859-
result = ops.where_method(self, cond, other)
860-
if isinstance(self, DataArray):
861-
result.name = self.name
862-
863-
return result
859+
return ops.where_method(self, cond, other)#result
864860

865861
def close(self):
866862
"""Close any files linked to this object

xarray/core/computation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def apply_dataarray_ufunc(func, *args, **kwargs):
199199
signature = kwargs.pop('signature')
200200
join = kwargs.pop('join', 'inner')
201201
exclude_dims = kwargs.pop('exclude_dims', _DEFAULT_FROZEN_SET)
202+
keep_attrs= kwargs.pop('keep_attrs', True)
202203
if kwargs:
203204
raise TypeError('apply_dataarray_ufunc() got unexpected keyword '
204205
'arguments: %s' % list(kwargs))
@@ -207,7 +208,10 @@ def apply_dataarray_ufunc(func, *args, **kwargs):
207208
args = deep_align(args, join=join, copy=False, exclude=exclude_dims,
208209
raise_on_invalid=False)
209210

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)
211215
result_coords = build_output_coords(args, signature, exclude_dims)
212216

213217
data_vars = [getattr(a, 'variable', a) for a in args]
@@ -986,7 +990,8 @@ def earth_mover_distance(first_samples,
986990
return apply_dataarray_ufunc(variables_ufunc, *args,
987991
signature=signature,
988992
join=join,
989-
exclude_dims=exclude_dims)
993+
exclude_dims=exclude_dims,
994+
keep_attrs=keep_attrs)
990995
elif any(isinstance(a, Variable) for a in args):
991996
return variables_ufunc(*args)
992997
else:

0 commit comments

Comments
 (0)