()
| 557 | |
| 558 | |
| 559 | def 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 | |
| 600 | def test_apply_groupby_add() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…