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

Function test_apply_exclude

xarray/tests/test_computation.py:559–597  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

557
558
559def test_apply_exclude() -> None:
560 def concatenate(objects, dim="x"):
561 def func(*x):
562 return np.concatenate(x, axis=-1)
563
564 result = apply_ufunc(
565 func,
566 *objects,
567 input_core_dims=[[dim]] * len(objects),
568 output_core_dims=[[dim]],
569 exclude_dims={dim},
570 )
571 if isinstance(result, xr.Dataset | xr.DataArray):
572 # note: this will fail if dim is not a coordinate on any input
573 new_coord = np.concatenate([obj.coords[dim] for obj in objects])
574 result.coords[dim] = new_coord
575 return result
576
577 arrays = [np.array([1]), np.array([2, 3])]
578 variables = [xr.Variable("x", a) for a in arrays]
579 data_arrays = [
580 xr.DataArray(v, {"x": c, "y": ("x", range(len(c)))})
581 for v, c in zip(variables, [["a"], ["b", "c"]], strict=True)
582 ]
583 datasets = [xr.Dataset({"data": data_array}) for data_array in data_arrays]
584
585 expected_array = np.array([1, 2, 3])
586 expected_variable = xr.Variable("x", expected_array)
587 expected_data_array = xr.DataArray(expected_variable, [("x", list("abc"))])
588 expected_dataset = xr.Dataset({"data": expected_data_array})
589
590 assert_identical(expected_array, concatenate(arrays))
591 assert_identical(expected_variable, concatenate(variables))
592 assert_identical(expected_data_array, concatenate(data_arrays))
593 assert_identical(expected_dataset, concatenate(datasets))
594
595 # must also be a core dimension
596 with pytest.raises(ValueError):
597 apply_ufunc(identity, variables[0], exclude_dims={"x"})
598
599
600def test_apply_groupby_add() -> None:

Callers

nothing calls this directly

Calls 3

apply_ufuncFunction · 0.90
assert_identicalFunction · 0.70
concatenateFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…