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

Function _write_dask_to_existing_zarr

dask/array/core.py:3792–3887  ·  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

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