()
| 598 | |
| 599 | |
| 600 | def test_apply_groupby_add() -> None: |
| 601 | array = np.arange(5) |
| 602 | variable = xr.Variable("x", array) |
| 603 | coords = {"x": -array, "y": ("x", [0, 0, 1, 1, 2])} |
| 604 | data_array = xr.DataArray(variable, coords, dims="x") |
| 605 | dataset = xr.Dataset({"z": variable}, coords) |
| 606 | |
| 607 | other_variable = xr.Variable("y", [0, 10]) |
| 608 | other_data_array = xr.DataArray(other_variable, dims="y") |
| 609 | other_dataset = xr.Dataset({"z": other_variable}) |
| 610 | |
| 611 | expected_variable = xr.Variable("x", [0, 1, 12, 13, np.nan]) |
| 612 | expected_data_array = xr.DataArray(expected_variable, coords, dims="x") |
| 613 | expected_dataset = xr.Dataset({"z": expected_variable}, coords) |
| 614 | |
| 615 | assert_identical( |
| 616 | expected_data_array, add(data_array.groupby("y"), other_data_array) |
| 617 | ) |
| 618 | assert_identical(expected_dataset, add(data_array.groupby("y"), other_dataset)) |
| 619 | assert_identical(expected_dataset, add(dataset.groupby("y"), other_data_array)) |
| 620 | assert_identical(expected_dataset, add(dataset.groupby("y"), other_dataset)) |
| 621 | |
| 622 | # cannot be performed with xarray.Variable objects that share a dimension |
| 623 | with pytest.raises(ValueError): |
| 624 | add(data_array.groupby("y"), other_variable) |
| 625 | |
| 626 | # if they are all grouped the same way |
| 627 | with pytest.raises(ValueError): |
| 628 | add(data_array.groupby("y"), data_array[:4].groupby("y")) |
| 629 | with pytest.raises(ValueError): |
| 630 | add(data_array.groupby("y"), data_array[1:].groupby("y")) |
| 631 | with pytest.raises(ValueError): |
| 632 | add(data_array.groupby("y"), other_data_array.groupby("y")) |
| 633 | with pytest.raises(ValueError): |
| 634 | add(data_array.groupby("y"), data_array.groupby("x")) |
| 635 | |
| 636 | |
| 637 | @pytest.mark.filterwarnings("ignore:Duplicate dimension names present") |
nothing calls this directly
no test coverage detected
searching dependent graphs…