Skip to content

Commit 67ccce2

Browse files
Ray Bellblackarywxman22
committed
add a test.
Co-authored-by: Zachary Blackwood <[email protected]> Co-authored-by: Nathan Lis <[email protected]>
1 parent e0ba649 commit 67ccce2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

xarray/backends/api.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,15 @@ def to_zarr(
13371337
else:
13381338
from fsspec import get_mapper
13391339

1340+
if not isinstance(store, str):
1341+
raise ValueError(
1342+
f"store must be a string to use storage_options. Got {type(store)}"
1343+
)
13401344
mapper = get_mapper(store, **storage_options)
1341-
chunk_mapper = get_mapper(chunk_store, **storage_options)
1345+
if chunk_store is not None:
1346+
chunk_mapper = get_mapper(chunk_store, **storage_options)
1347+
else:
1348+
chunk_mapper = chunk_store
13421349

13431350
if encoding is None:
13441351
encoding = {}

xarray/backends/zarr.py

+3
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ def open_zarr(
713713
falling back to read non-consolidated metadata if that fails.
714714
chunk_store : MutableMapping, optional
715715
A separate Zarr store only for chunk data.
716+
storage_options : dict, optional
717+
Any additional parameters for the storage backend (ignored for local
718+
paths).
716719
decode_timedelta : bool, optional
717720
If True, decode variables and coordinates with time units in
718721
{'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds'}

xarray/tests/test_backends.py

+9
Original file line numberDiff line numberDiff line change
@@ -2388,6 +2388,15 @@ def create_zarr_target(self):
23882388
yield tmp
23892389

23902390

2391+
@requires_fsspec
2392+
def test_zarr_storage_options():
2393+
ds = create_test_data()
2394+
store_target = "memory://test.zarr"
2395+
ds.to_zarr(store_target, storage_options={"test": "zarr_write"})
2396+
ds_a = xr.open_zarr(store_target, storage_options={"test": "zarr_read"})
2397+
assert_identical(ds, ds_a)
2398+
2399+
23912400
@requires_scipy
23922401
class TestScipyInMemoryData(CFEncodedBase, NetCDF3Only):
23932402
engine = "scipy"

0 commit comments

Comments
 (0)