Skip to content

Commit 37ae37b

Browse files
authored
fix: defer to fsspec for memory url scheme (#3944)
* fix: defer to fsspec for memory url scheme * docs: changelog * test: add test for the memory scheme : memoryfilesystem mapping
1 parent 021662c commit 37ae37b

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

changes/3944.bugfix.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixed breakage in existing fsspec-dependent workflows caused by associating the "memory" URL scheme with
2+
instances of `ManagedMemoryStore` instead of fsspec's memory-backed store. After this change, store URLs with a "memory" scheme are handled differently when `fsspec` is installed:
3+
with `fsspec`, a `FsspecStore` backed by a `MemoryFileSystem` is used. Without `fsspec`,
4+
a `ManagedMemoryStore` is used.

src/zarr/storage/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ async def make_store(
369369
return await LocalStore.open(root=store_like, mode=mode, read_only=_read_only)
370370

371371
elif isinstance(store_like, str) and parsed is not None:
372-
if parsed.scheme == "memory":
372+
if parsed.scheme == "memory" and not _has_fsspec:
373373
# Create or get a ManagedMemoryStore
374374
return ManagedMemoryStore(name=parsed.name, path=parsed.path, read_only=_read_only)
375375
elif parsed.scheme == "file" or not parsed.scheme:

tests/test_store/test_fsspec.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from zarr.core.sync import _collect_aiterator, sync
1717
from zarr.errors import ZarrUserWarning
1818
from zarr.storage import FsspecStore
19+
from zarr.storage._common import make_store
1920
from zarr.storage._fsspec import _make_async
2021
from zarr.testing.store import StoreTests
2122

@@ -544,3 +545,14 @@ async def test_with_read_only_auto_mkdir(tmp_path: Path) -> None:
544545

545546
store_w = FsspecStore.from_url(f"file://{tmp_path}", storage_options={"auto_mkdir": False})
546547
_ = store_w.with_read_only()
548+
549+
550+
@pytest.mark.skipif(
551+
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
552+
reason="No AsyncFileSystemWrapper",
553+
)
554+
async def test_memory_scheme() -> None:
555+
"""Test that the "memory" scheme creates a `MemoryFileSystem`-backed store"""
556+
store = await make_store("memory://test")
557+
assert isinstance(store, FsspecStore)
558+
assert store.fs.protocol == "memory"

0 commit comments

Comments
 (0)