Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure zarr.create uses writeable mode #1309

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zarr/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
zarr_version = getattr(chunk_store, '_store_version', DEFAULT_ZARR_VERSION)

# handle polymorphic store arg
store = normalize_store_arg(store, zarr_version=zarr_version)
store = normalize_store_arg(store, zarr_version=zarr_version, mode="w")
zarr_version = getattr(store, '_store_version', DEFAULT_ZARR_VERSION)

# API compatibility with h5py
Expand Down
14 changes: 13 additions & 1 deletion zarr/tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from zarr._storage.store import v3_api_available
from zarr._storage.v3 import DirectoryStoreV3, KVStoreV3
from zarr.sync import ThreadSynchronizer
from zarr.tests.util import mktemp
from zarr.tests.util import mktemp, have_fsspec

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


@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fsspec needed to reproduce this bug? In my reading of the code, it it should only affect stores that have a mode argument in their constructor. That is:

  • FSStore
  • ZipStore
  • DBMStore

The fact that not all stores accept the mode keyword it, to me, a Zarr code smell.

@pytest.mark.parametrize('zarr_version', _VERSIONS)
@pytest.mark.parametrize('at_root', [False, True])
def test_create_writeable_mode(zarr_version, at_root, tmp_path):
# Regression test for https://github.com/zarr-developers/zarr-python/issues/1306
import fsspec
kwargs = _init_creation_kwargs(zarr_version, at_root)
store = fsspec.get_mapper(str(tmp_path))
z = create(100, store=store, **kwargs)
assert z.store.map == store


@pytest.mark.parametrize('zarr_version', _VERSIONS)
@pytest.mark.parametrize('at_root', [False, True])
def test_empty_like(zarr_version, at_root):
Expand Down