4141
4242
4343def _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
4951class _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