Apply a variable level function over dicts of DataArray, DataArray, Variable and ndarray objects.
(
func,
*args,
signature: _UFuncSignature,
join="inner",
fill_value=None,
on_missing_core_dim: MissingCoreDimOptions = "raise",
)
| 431 | |
| 432 | |
| 433 | def apply_dict_of_variables_vfunc( |
| 434 | func, |
| 435 | *args, |
| 436 | signature: _UFuncSignature, |
| 437 | join="inner", |
| 438 | fill_value=None, |
| 439 | on_missing_core_dim: MissingCoreDimOptions = "raise", |
| 440 | ): |
| 441 | """Apply a variable level function over dicts of DataArray, DataArray, |
| 442 | Variable and ndarray objects. |
| 443 | """ |
| 444 | args = tuple(_as_variables_or_variable(arg) for arg in args) |
| 445 | names = join_dict_keys(args, how=join) |
| 446 | grouped_by_name = collect_dict_values(args, names, fill_value) |
| 447 | |
| 448 | result_vars = {} |
| 449 | for name, variable_args in zip(names, grouped_by_name, strict=True): |
| 450 | core_dim_present = _check_core_dims(signature, variable_args, name) |
| 451 | if core_dim_present is True: |
| 452 | result_vars[name] = func(*variable_args) |
| 453 | elif on_missing_core_dim == "raise": |
| 454 | raise ValueError(core_dim_present) |
| 455 | elif on_missing_core_dim == "copy": |
| 456 | result_vars[name] = variable_args[0] |
| 457 | elif on_missing_core_dim == "drop": |
| 458 | pass |
| 459 | else: |
| 460 | raise ValueError( |
| 461 | f"Invalid value for `on_missing_core_dim`: {on_missing_core_dim!r}" |
| 462 | ) |
| 463 | |
| 464 | if signature.num_outputs > 1: |
| 465 | return _unpack_dict_tuples(result_vars, signature.num_outputs) |
| 466 | else: |
| 467 | return result_vars |
| 468 | |
| 469 | |
| 470 | def _fast_dataset( |
no test coverage detected
searching dependent graphs…