10000 Ensure zarr.create uses writeable mode · zarr-developers/zarr-python@381111b · GitHub
[go: up one dir, main page]

Skip to content

Commit 381111b

Browse files
committed
Ensure zarr.create uses writeable mode
1 parent 4e633ad commit 381111b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

zarr/creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
145145
zarr_version = getattr(chunk_store, '_store_version', DEFAULT_ZARR_VERSION)
146146

147147
# handle polymorphic store arg
148-
store = normalize_store_arg(store, zarr_version=zarr_version)
148+
store = normalize_store_arg(store, zarr_version=zarr_version, mode="w")
149149
zarr_version = getattr(store, '_store_version', DEFAULT_ZARR_VERSION)
150150

151151
# API compatibility with h5py

zarr/tests/test_creation.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from zarr._storage.store import v3_api_available
2020
from zarr._storage.v3 import DirectoryStoreV3, KVStoreV3
2121
from zarr.sync import ThreadSynchronizer
22-
from zarr.tests.util import mktemp
22+
from zarr.tests.util import mktemp, have_fsspec
2323

2424
_VERSIONS = ((None, 2, 3) if v3_api_available else (None, 2))
2525
_VERSIONS2 = ((2, 3) if v3_api_available else (2, ))
@@ -429,6 +429,18 @@ def test_create_in_dict(zarr_version, at_root):
429429
assert isinstance(a.store, expected_store_type)
430430

431431

432+
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
433+
@pytest.mark.parametrize('zarr_version', _VERSIONS)
434+
@pytest.mark.parametrize('at_root', [False, True])
435+
def test_create_writeable_mode(zarr_version, at_root, tmp_path):
436+
# Regression test for https://github.com/zarr-developers/zarr-python/issues/1306
437+
import fsspec
438+
kwargs = _init_creation_kwargs(zarr_version, at_root)
439+
store = fsspec.get_mapper(str(tmp_path))
440+
z = create(100, store=store, **kwargs)
441+
assert z.store.map == store
442+
443+
432444
@pytest.mark.parametrize('zarr_version', _VERSIONS)
433445
@pytest.mark.parametrize('at_root', [False, True])
434446
def test_empty_like(zarr_version, at_root):

0 commit comments

Comments
 (0)
0