Skip to content

Commit 092edea

Browse files
committed
review comments
1 parent 564046b commit 092edea

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

doc/whats-new.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ New Features
4949
now accept a ``dim_order`` parameter allowing to specify the resulting dataframe's
5050
dimensions order (:issue:`4331`, :pull:`4333`).
5151
By `Thomas Zilio <https://github.com/thomas-z>`_.
52-
- More operations follow the ``keep_attrs`` flag (:issue:`3490`, :issue:`4065`, :issue:`3433`, :issue:`3595`, :pull:`4195`).
52+
- Unary & binary operations follow the ``keep_attrs`` flag (:issue:`3490`, :issue:`4065`, :issue:`3433`, :issue:`3595`, :pull:`4195`).
5353
By `Deepak Cherian <https://github.com/dcherian>`_.
5454

5555

xarray/core/computation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141

4242

4343
def _first_of_type(args, kind):
44+
"""" Returns either first object of type 'kind' or None if not found. """
4445
for arg in args:
4546
if isinstance(arg, kind):
4647
return arg
48+
raise NotImplementedError("This should be unreachable.")
4749

4850

4951
class _UFuncSignature:
@@ -231,7 +233,7 @@ def apply_dataarray_vfunc(
231233

232234
first_obj = _first_of_type(args, DataArray)
233235

234-
if keep_attrs and hasattr(first_obj, "name"):
236+
if keep_attrs:
235237
name = first_obj.name
236238
else:
237239
name = result_name(args)
@@ -249,7 +251,7 @@ def apply_dataarray_vfunc(
249251
(coords,) = result_coords
250252
out = DataArray(result_var, coords, name=name, fastpath=True)
251253

252-
if keep_attrs and hasattr(first_obj, "attrs"):
254+
if keep_attrs:
253255
if isinstance(out, tuple):
254256
for da in out:
255257
# This is adding attrs in place
@@ -404,7 +406,7 @@ def apply_dataset_vfunc(
404406
(coord_vars,) = list_of_coords
405407
out = _fast_dataset(result_vars, coord_vars)
406408

407-
if keep_attrs and isinstance(first_obj, Dataset):
409+
if keep_attrs:
408410
if isinstance(out, tuple):
409411
for ds in out:
410412
# This is adding attrs in place
@@ -658,7 +660,7 @@ def func(*arrays):
658660
)
659661
)
660662

661-
if keep_attrs and isinstance(first_obj, Variable):
663+
if keep_attrs:
662664
var.attrs.update(first_obj.attrs)
663665
output.append(var)
664666

0 commit comments

Comments
 (0)