Skip to content

Commit

Permalink
shoyer's solution
Browse files Browse the repository at this point in the history
  • Loading branch information
yohai committed Feb 9, 2019
1 parent 27ed788 commit 71a6b1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 1 addition & 5 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,7 @@ def where(self, cond, other=dtypes.NA, drop=False):
self = self.isel(**indexers)
cond = cond.isel(**indexers)

result = ops.where_method(self, cond, other)
if isinstance(self, DataArray):
result.name = self.name

return result
return ops.where_method(self, cond, other)#result

def close(self):
"""Close any files linked to this object
Expand Down
9 changes: 7 additions & 2 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def apply_dataarray_ufunc(func, *args, **kwargs):
signature = kwargs.pop('signature')
join = kwargs.pop('join', 'inner')
exclude_dims = kwargs.pop('exclude_dims', _DEFAULT_FROZEN_SET)
keep_attrs= kwargs.pop('keep_attrs', True)
if kwargs:
raise TypeError('apply_dataarray_ufunc() got unexpected keyword '
'arguments: %s' % list(kwargs))
Expand All @@ -207,7 +208,10 @@ def apply_dataarray_ufunc(func, *args, **kwargs):
args = deep_align(args, join=join, copy=False, exclude=exclude_dims,
raise_on_invalid=False)

name = result_name(args)
if keep_attrs and hasattr(args[0], 'name'):
name = args[0].name
else:
name = result_name(args)
result_coords = build_output_coords(args, signature, exclude_dims)

data_vars = [getattr(a, 'variable', a) for a in args]
Expand Down Expand Up @@ -986,7 +990,8 @@ def earth_mover_distance(first_samples,
return apply_dataarray_ufunc(variables_ufunc, *args,
signature=signature,
join=join,
exclude_dims=exclude_dims)
exclude_dims=exclude_dims,
keep_attrs=keep_attrs)
elif any(isinstance(a, Variable) for a in args):
return variables_ufunc(*args)
else:
Expand Down

0 comments on commit 71a6b1c

Please sign in to comment.