MCPcopy
hub / github.com/pydata/xarray / apply_dataarray_vfunc

Function apply_dataarray_vfunc

xarray/computation/apply_ufunc.py:276–338  ·  view source on GitHub ↗

Apply a variable level function over DataArray, Variable and/or ndarray objects.

(
    func,
    *args,
    signature: _UFuncSignature,
    join: JoinOptions = "inner",
    exclude_dims=frozenset(),
    keep_attrs="override",
)

Source from the content-addressed store, hash-verified

274
275
276def apply_dataarray_vfunc(
277 func,
278 *args,
279 signature: _UFuncSignature,
280 join: JoinOptions = "inner",
281 exclude_dims=frozenset(),
282 keep_attrs="override",
283) -> tuple[DataArray, ...] | DataArray:
284 """Apply a variable level function over DataArray, Variable and/or ndarray
285 objects.
286 """
287 from xarray.core.dataarray import DataArray
288
289 if len(args) > 1:
290 args = tuple(
291 deep_align(
292 args,
293 join=join,
294 copy=False,
295 exclude=exclude_dims,
296 raise_on_invalid=False,
297 )
298 )
299
300 objs = _all_of_type(args, DataArray)
301
302 if keep_attrs == "drop":
303 name = result_name(args)
304 else:
305 first_obj = _first_of_type(args, DataArray)
306 name = first_obj.name
307 result_coords, result_indexes = build_output_coords_and_indexes(
308 args, signature, exclude_dims, combine_attrs=keep_attrs
309 )
310
311 data_vars = [getattr(a, "variable", a) for a in args]
312 result_var = func(*data_vars)
313
314 out: tuple[DataArray, ...] | DataArray
315 if signature.num_outputs > 1:
316 out = tuple(
317 DataArray(
318 variable, coords=coords, indexes=indexes, name=name, fastpath=True
319 )
320 for variable, coords, indexes in zip(
321 result_var, result_coords, result_indexes, strict=True
322 )
323 )
324 else:
325 (coords,) = result_coords
326 (indexes,) = result_indexes
327 out = DataArray(
328 result_var, coords=coords, indexes=indexes, name=name, fastpath=True
329 )
330
331 attrs = merge_attrs([x.attrs for x in objs], combine_attrs=keep_attrs)
332 if isinstance(out, tuple):
333 for da in out:

Callers 1

apply_ufuncFunction · 0.85

Calls 8

deep_alignFunction · 0.90
result_nameFunction · 0.90
DataArrayClass · 0.90
merge_attrsFunction · 0.90
_all_of_typeFunction · 0.85
_first_of_typeFunction · 0.85
funcFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…