| 5268 | |
| 5269 | |
| 5270 | def test_zarr_regions(): |
| 5271 | zarr = pytest.importorskip("zarr") |
| 5272 | |
| 5273 | a = da.arange(16).reshape((4, 4)).rechunk(2) |
| 5274 | z = zarr.zeros_like(a, chunks=2) |
| 5275 | |
| 5276 | a[:2, :2].to_zarr(z, region=(slice(2), slice(2))) |
| 5277 | a2 = da.from_zarr(z) |
| 5278 | expected = [[0, 1, 0, 0], [4, 5, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] |
| 5279 | assert_eq(a2, expected) |
| 5280 | assert a2.chunks == a.chunks |
| 5281 | |
| 5282 | with pytest.warns(PerformanceWarning): |
| 5283 | a[:3, 3:4].to_zarr(z, region=(slice(1, 4), slice(2, 3))) |
| 5284 | |
| 5285 | a2 = da.from_zarr(z) |
| 5286 | expected = [[0, 1, 0, 0], [4, 5, 3, 0], [0, 0, 7, 0], [0, 0, 11, 0]] |
| 5287 | assert_eq(a2, expected) |
| 5288 | assert a2.chunks == a.chunks |
| 5289 | |
| 5290 | with pytest.warns(PerformanceWarning): |
| 5291 | a[3:, 3:].to_zarr(z, region=(slice(2, 3), slice(1, 2))) |
| 5292 | |
| 5293 | a2 = da.from_zarr(z) |
| 5294 | expected = [[0, 1, 0, 0], [4, 5, 3, 0], [0, 15, 7, 0], [0, 0, 11, 0]] |
| 5295 | assert_eq(a2, expected) |
| 5296 | assert a2.chunks == a.chunks |
| 5297 | |
| 5298 | with pytest.raises(ValueError): |
| 5299 | with tmpdir() as d: |
| 5300 | a.to_zarr(d, region=(slice(2), slice(2))) |
| 5301 | |
| 5302 | |
| 5303 | def test_tiledb_roundtrip(): |