(map_ds)
| 1124 | |
| 1125 | |
| 1126 | def test_unify_chunks(map_ds): |
| 1127 | ds_copy = map_ds.copy() |
| 1128 | ds_copy["cxy"] = ds_copy.cxy.chunk({"y": 10}) |
| 1129 | |
| 1130 | with pytest.raises(ValueError, match=r"inconsistent chunks"): |
| 1131 | _ = ds_copy.chunks |
| 1132 | |
| 1133 | expected_chunks = {"x": (4, 4, 2), "y": (5, 5, 5, 5)} |
| 1134 | with raise_if_dask_computes(): |
| 1135 | actual_chunks = ds_copy.unify_chunks().chunks |
| 1136 | assert actual_chunks == expected_chunks |
| 1137 | assert_identical(map_ds, ds_copy.unify_chunks()) |
| 1138 | |
| 1139 | out_a, out_b = xr.unify_chunks(ds_copy.cxy, ds_copy.drop_vars("cxy")) |
| 1140 | assert out_a.chunks == ((4, 4, 2), (5, 5, 5, 5)) |
| 1141 | assert out_b.chunks == expected_chunks |
| 1142 | |
| 1143 | # Test unordered dims |
| 1144 | da = ds_copy["cxy"] |
| 1145 | out_a, out_b = xr.unify_chunks(da.chunk({"x": -1}), da.T.chunk({"y": -1})) |
| 1146 | assert out_a.chunks == ((4, 4, 2), (5, 5, 5, 5)) |
| 1147 | assert out_b.chunks == ((5, 5, 5, 5), (4, 4, 2)) |
| 1148 | |
| 1149 | # Test mismatch |
| 1150 | with pytest.raises(ValueError, match=r"Dimension 'x' size mismatch: 10 != 2"): |
| 1151 | xr.unify_chunks(da, da.isel(x=slice(2))) |
| 1152 | |
| 1153 | |
| 1154 | @pytest.mark.parametrize("obj", [make_ds(), make_da()]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…