Skip to content

Commit fa87b9f

Browse files
committed
Allow use of obstore in Zarr by setting 'use_obstore' in 'storage_options'
1 parent 3571409 commit fa87b9f

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

cubed/storage/backends/zarr_python_v3.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from typing import Optional
23

34
import zarr
@@ -39,6 +40,22 @@ def open_zarr_v3_array(
3940
path: Optional[str] = None,
4041
**kwargs,
4142
):
43+
# use obstore if requested
44+
storage_options = kwargs.get("storage_options", None)
45+
if storage_options is not None and storage_options.get("use_obstore", False):
46+
import obstore as obs
47+
from zarr.storage import ObjectStore
48+
49+
if isinstance(store, str):
50+
if "://" not in store:
51+
p = Path(store)
52+
store = ObjectStore(obs.store.from_url(p.as_uri(), mkdir=True))
53+
else:
54+
store = ObjectStore(obs.store.from_url(store))
55+
elif isinstance(store, Path):
56+
p = store
57+
store = ObjectStore(obs.store.from_url(p.as_uri(), mkdir=True))
58+
4259
if isinstance(chunks, int):
4360
chunks = (chunks,)
4461

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ ignore_missing_imports = True
4747
ignore_missing_imports = True
4848
[mypy-numpy.*]
4949
ignore_missing_imports = True
50+
[mypy-obstore.*]
51+
ignore_missing_imports = True
5052
[mypy-pandas.*]
5153
ignore_missing_imports = True
5254
[mypy-psutil.*]

0 commit comments

Comments
 (0)