| 5289 | |
| 5290 | |
| 5291 | def test_zarr_regions(): |
| 5292 | zarr = pytest.importorskip("zarr") |
| 5293 | |
| 5294 | a = da.arange(16).reshape((4, 4)).rechunk(2) |
| 5295 | z = zarr.zeros_like(a, chunks=2) |
| 5296 | |
| 5297 | a[:2, :2].to_zarr(z, region=(slice(2), slice(2))) |
| 5298 | a2 = da.from_zarr(z) |
| 5299 | expected = [[0, 1, 0, 0], [4, 5, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] |
| 5300 | assert_eq(a2, expected) |
| 5301 | assert a2.chunks == a.chunks |
| 5302 | |
| 5303 | with pytest.warns(PerformanceWarning): |
| 5304 | a[:3, 3:4].to_zarr(z, region=(slice(1, 4), slice(2, 3))) |
| 5305 | |
| 5306 | a2 = da.from_zarr(z) |
| 5307 | expected = [[0, 1, 0, 0], [4, 5, 3, 0], [0, 0, 7, 0], [0, 0, 11, 0]] |
| 5308 | assert_eq(a2, expected) |
| 5309 | assert a2.chunks == a.chunks |
| 5310 | |
| 5311 | with pytest.warns(PerformanceWarning): |
| 5312 | a[3:, 3:].to_zarr(z, region=(slice(2, 3), slice(1, 2))) |
| 5313 | |
| 5314 | a2 = da.from_zarr(z) |
| 5315 | expected = [[0, 1, 0, 0], [4, 5, 3, 0], [0, 15, 7, 0], [0, 0, 11, 0]] |
| 5316 | assert_eq(a2, expected) |
| 5317 | assert a2.chunks == a.chunks |
| 5318 | |
| 5319 | with pytest.raises(ValueError): |
| 5320 | with tmpdir() as d: |
| 5321 | a.to_zarr(d, region=(slice(2), slice(2))) |
| 5322 | |
| 5323 | |
| 5324 | def test_tiledb_roundtrip(): |