MCPcopy Create free account
hub / github.com/dask/dask / _write_dask_to_existing_zarr

Function _write_dask_to_existing_zarr

dask/array/core.py:3797–3892  ·  view source on GitHub ↗

Write dask array to existing zarr store. Parameters ---------- url: zarr.Array The zarr array. arr: The dask array to be stored region: tuple of slices or None The region of data that should be written if ``url`` is a zarr.Array. Not to be used wi

(
    url, arr, region, zarr_mem_store_types, compute, return_stored
)

Source from the content-addressed store, hash-verified

3795
3796
3797def _write_dask_to_existing_zarr(
3798 url, arr, region, zarr_mem_store_types, compute, return_stored
3799):
3800 """Write dask array to existing zarr store.
3801
3802 Parameters
3803 ----------
3804 url: zarr.Array
3805 The zarr array.
3806 arr:
3807 The dask array to be stored
3808 region: tuple of slices or None
3809 The region of data that should be written if ``url`` is a zarr.Array.
3810 Not to be used with other types of ``url``.
3811 zarr_mem_store_types: tuple[Type[dict] | Type[zarr.storage.MemoryStore] | Type[zarr.storage.KVStore], ...]
3812 The type of zarr memory store that is allowed.
3813 compute: bool
3814 See :func:`~dask.array.store` for more details.
3815 return_stored: bool
3816 See :func:`~dask.array.store` for more details.
3817
3818 Returns
3819 -------
3820 If return_stored=True
3821 tuple of Arrays
3822 If return_stored=False and compute=True
3823 None
3824 If return_stored=False and compute=False
3825 Delayed
3826 """
3827 z = url
3828 if isinstance(z.store, zarr_mem_store_types):
3829 try:
3830 from distributed import default_client
3831
3832 default_client()
3833 except (ImportError, ValueError):
3834 pass
3835 else:
3836 raise RuntimeError(
3837 "Cannot store into in memory Zarr Array using "
3838 "the distributed scheduler."
3839 )
3840 zarr_write_chunks = _get_zarr_write_chunks(z)
3841 dask_write_chunks = normalize_chunks(
3842 chunks="auto",
3843 shape=z.shape,
3844 dtype=z.dtype,
3845 previous_chunks=zarr_write_chunks,
3846 )
3847
3848 if region is not None:
3849 from dask.array.slicing import new_blockdim, normalize_index
3850
3851 index = normalize_index(region, z.shape)
3852 dask_write_chunks = tuple(
3853 tuple(new_blockdim(s, c, r))
3854 for s, c, r in zip(z.shape, dask_write_chunks, index)

Callers 1

to_zarrFunction · 0.85

Calls 8

normalize_indexFunction · 0.90
new_blockdimFunction · 0.90
maxFunction · 0.90
_get_zarr_write_chunksFunction · 0.85
normalize_chunksFunction · 0.85
storeMethod · 0.80
prodMethod · 0.45
rechunkMethod · 0.45

Tested by

no test coverage detected