Skip to content

Commit

Permalink
Update zarr store creation functions (#9790)
Browse files Browse the repository at this point in the history
As discussed in zarr-developers/zarr-python#1309 (review), Zarr can now handle a the creation of more types of store object from URLs thanks to the FSStore class. This means that usually Dask can just pass through the store URL with no modifications (e.g. calling get_mapper). The only exception is when the user specifies storage_options explicitly
  • Loading branch information
rabernat authored Dec 30, 2022
1 parent 40bc376 commit 0cd60ee
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dask/array/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from typing import Any, TypeVar, Union, cast

import numpy as np
from fsspec import get_mapper
from tlz import accumulate, concat, first, frequencies, groupby, partition
from tlz.curried import pluck

Expand Down Expand Up @@ -3562,11 +3561,13 @@ def from_zarr(
elif isinstance(url, (str, os.PathLike)):
if isinstance(url, os.PathLike):
url = os.fspath(url)
mapper = get_mapper(url, **storage_options)
z = zarr.Array(mapper, read_only=True, path=component, **kwargs)
if storage_options:
store = zarr.storage.FSStore(url, **storage_options)
else:
store = url
z = zarr.Array(store, read_only=True, path=component, **kwargs)
else:
mapper = url
z = zarr.Array(mapper, read_only=True, path=component, **kwargs)
z = zarr.Array(url, read_only=True, path=component, **kwargs)
chunks = chunks if chunks is not None else z.chunks
if name is None:
name = "from-zarr-" + tokenize(z, component, storage_options, chunks, **kwargs)
Expand Down Expand Up @@ -3674,19 +3675,18 @@ def to_zarr(

storage_options = storage_options or {}

if isinstance(url, str):
mapper = get_mapper(url, **storage_options)
if storage_options:
store = zarr.storage.FSStore(url, **storage_options)
else:
# assume the object passed is already a mapper
mapper = url
store = url

chunks = [c[0] for c in arr.chunks]

z = zarr.create(
shape=arr.shape,
chunks=chunks,
dtype=arr.dtype,
store=mapper,
store=store,
path=component,
overwrite=overwrite,
**kwargs,
Expand Down

0 comments on commit 0cd60ee

Please sign in to comment.