MCPcopy
hub / github.com/pydata/xarray / test_write_region

Method test_write_region

xarray/tests/test_backends.py:3470–3506  ·  view source on GitHub ↗
(self, consolidated, compute, use_dask, write_empty)

Source from the content-addressed store, hash-verified

3468 @pytest.mark.parametrize("use_dask", [False, True])
3469 @pytest.mark.parametrize("write_empty", [False, True, None])
3470 def test_write_region(self, consolidated, compute, use_dask, write_empty) -> None:
3471 if (use_dask or not compute) and not has_dask:
3472 pytest.skip("requires dask")
3473
3474 zeros = Dataset({"u": (("x",), np.zeros(10))})
3475 nonzeros = Dataset({"u": (("x",), np.arange(1, 11))})
3476
3477 if use_dask:
3478 zeros = zeros.chunk(2)
3479 nonzeros = nonzeros.chunk(2)
3480
3481 with self.create_zarr_target() as store:
3482 zeros.to_zarr(
3483 store,
3484 consolidated=consolidated,
3485 compute=compute,
3486 encoding={"u": dict(chunks=2)},
3487 **self.version_kwargs,
3488 )
3489 if compute:
3490 with xr.open_zarr(
3491 store, consolidated=consolidated, **self.version_kwargs
3492 ) as actual:
3493 assert_identical(actual, zeros)
3494 for i in range(0, 10, 2):
3495 region = {"x": slice(i, i + 2)}
3496 nonzeros.isel(region).to_zarr(
3497 store,
3498 region=region,
3499 consolidated=consolidated,
3500 write_empty_chunks=write_empty,
3501 **self.version_kwargs,
3502 )
3503 with xr.open_zarr(
3504 store, consolidated=consolidated, **self.version_kwargs
3505 ) as actual:
3506 assert_identical(actual, nonzeros)
3507
3508 def test_region_scalar(self) -> None:
3509 ds = Dataset({"x": 0})

Callers

nothing calls this directly

Calls 7

chunkMethod · 0.95
create_zarr_targetMethod · 0.95
to_zarrMethod · 0.95
iselMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
arangeMethod · 0.80

Tested by

no test coverage detected