Repository: dask/dask
File: dask/array/core.py (Python)

Code before:

    Raises
    ------
    ValueError
        If ``arr`` has unknown chunk sizes, which is not supported by Zarr.
        If ``region`` is specified and ``url`` is not a zarr.Array

    See Also
    --------
    dask.array.store
    dask.array.Array.compute_chunk_sizes

    """
    import zarr

    if np.isnan(arr.shape).any():
        raise ValueError(
            "Saving a dask array with unknown chunk sizes is not "
            f"currently supported by Zarr.{unknown_chunk_message}"
        )

    if kwargs:
        warnings.warn(
            "Passing storage-related arguments via **kwargs is deprecated. "
            "Please use the 'zarr_store_kwargs' parameter instead.",
            DeprecationWarning,
            stacklevel=2,
        )
        if zarr_read_kwargs is None:
            zarr_read_kwargs = kwargs
        else:
            zarr_read_kwargs = {**kwargs, **zarr_read_kwargs}

    if _zarr_v3():
        zarr_mem_store_types = (zarr.storage.MemoryStore,)
    else:
        zarr_mem_store_types = (dict, zarr.storage.MemoryStore, zarr.storage.KVStore)

    if isinstance(url, zarr.Array):
        return _write_dask_to_existing_zarr(
            url, arr, region, zarr_mem_store_types, compute, return_stored
        )

    if not _check_regular_chunks(arr.chunks):
        warnings.warn(
            "The array uses irregular chunk sizes. Rechunking to regular (uniform) chunks "
            "to ensure the data can be written safely. If you want to avoid this automatic "
            "rechunking, manually rechunk the array so that all chunks, except possibly the "
            "final chunk, in each dimension—have the same size (e.g., arr = arr.rechunk(...)).",
            UserWarning,
            stacklevel=2,

Review comment (suggestion):
This should probably be a `FutureWarning` so that it's always visible to users.

Code after:
        if zarr_read_kwargs is None:
            zarr_read_kwargs = kwargs
        else:
            zarr_read_kwargs = {**kwargs, **zarr_read_kwargs}

    if _zarr_v3():
        zarr_mem_store_types = (zarr.storage.MemoryStore,)
    else:
        zarr_mem_store_types = (dict, zarr.storage.MemoryStore, zarr.storage.KVStore)

    if isinstance(url, zarr.Array):
        return _write_dask_to_existing_zarr(
            url, arr, region, zarr_mem_store_types, compute, return_stored
        )

    if not _check_regular_chunks(arr.chunks):
        warnings.warn(
            "The array uses irregular chunk sizes. Rechunking to regular (uniform) chunks "
            "to ensure the data can be written safely. If you want to avoid this automatic "
            "rechunking, manually rechunk the array so that all chunks, except possibly the "
            "final chunk, in each dimension—have the same size (e.g., arr = arr.rechunk(...)).",
            UserWarning,
            stacklevel=2,
        )
        # We almost certainly get here because auto chunking has been used
        # on irregular chunks. The max will then be smaller than auto, so using
        # max is a safe choice
        arr = arr.rechunk(tuple(map(max, arr.chunks)))

    if region is not None:
        raise ValueError("Cannot use `region` keyword when url is not a `zarr.Array`.")

    zarr_read_kwargs = {} if zarr_read_kwargs is None else dict(zarr_read_kwargs)
    zarr_store = _setup_zarr_store(url, storage_options, **zarr_read_kwargs)

    zarr_array_kwargs.setdefault("shape", arr.shape)
    zarr_array_kwargs.setdefault("chunks", tuple(c[0] for c in arr.chunks))
    zarr_array_kwargs.setdefault("dtype", arr.dtype)

    array_name = component or zarr_array_kwargs.pop("name", None)
    if _zarr_v3():
        root = zarr.open_group(store=zarr_store, mode="a") if array_name else None
        if array_name:
            z = root.create_array(name=array_name, **zarr_array_kwargs)
        else:
            zarr_array_kwargs["store"] = zarr_store
            z = zarr.create_array(**zarr_array_kwargs)
    else:
        # TODO: drop this as soon as zarr v2 gets dropped.
        # https://github.com/dask/dask/issues/12188
        z = zarr.create(