(self)
| 2823 | xr.align(ds, ds.copy(), join="exact") |
| 2824 | |
| 2825 | def test_broadcast(self) -> None: |
| 2826 | ds = Dataset( |
| 2827 | {"foo": 0, "bar": ("x", [1]), "baz": ("y", [2, 3])}, {"c": ("x", [4])} |
| 2828 | ) |
| 2829 | expected = Dataset( |
| 2830 | { |
| 2831 | "foo": (("x", "y"), [[0, 0]]), |
| 2832 | "bar": (("x", "y"), [[1, 1]]), |
| 2833 | "baz": (("x", "y"), [[2, 3]]), |
| 2834 | }, |
| 2835 | {"c": ("x", [4])}, |
| 2836 | ) |
| 2837 | (actual,) = broadcast(ds) |
| 2838 | assert_identical(expected, actual) |
| 2839 | |
| 2840 | ds_x = Dataset({"foo": ("x", [1])}) |
| 2841 | ds_y = Dataset({"bar": ("y", [2, 3])}) |
| 2842 | expected_x = Dataset({"foo": (("x", "y"), [[1, 1]])}) |
| 2843 | expected_y = Dataset({"bar": (("x", "y"), [[2, 3]])}) |
| 2844 | actual_x, actual_y = broadcast(ds_x, ds_y) |
| 2845 | assert_identical(expected_x, actual_x) |
| 2846 | assert_identical(expected_y, actual_y) |
| 2847 | |
| 2848 | array_y = ds_y["bar"] |
| 2849 | expected_y2 = expected_y["bar"] |
| 2850 | actual_x2, actual_y2 = broadcast(ds_x, array_y) |
| 2851 | assert_identical(expected_x, actual_x2) |
| 2852 | assert_identical(expected_y2, actual_y2) |
| 2853 | |
| 2854 | def test_broadcast_nocopy(self) -> None: |
| 2855 | # Test that data is not copied if not needed |
nothing calls this directly
no test coverage detected