Skip to content

Remove breaking check about auto_mkdir for FSSpecStore #3193

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

Merged
merged 7 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions changes/3193.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Removed an unnecessary check from ``_fsspec._make_async`` that would raise an exception when
creating a read-only store backed by a local file system with ``auto_mkdir`` set to ``False``.
6 changes: 0 additions & 6 deletions src/zarr/storage/_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,12 @@ def _make_async(fs: AbstractFileSystem) -> AsyncFileSystem:
fs_dict["asynchronous"] = True
return fsspec.AbstractFileSystem.from_json(json.dumps(fs_dict))

# Wrap sync filesystems with the async wrapper
if type(fs) is fsspec.implementations.local.LocalFileSystem and not fs.auto_mkdir:
raise ValueError(
f"LocalFilesystem {fs} was created with auto_mkdir=False but Zarr requires the filesystem to automatically create directories"
)
if fsspec_version < parse_version("2024.12.0"):
raise ImportError(
f"The filesystem '{fs}' is synchronous, and the required "
"AsyncFileSystemWrapper is not available. Upgrade fsspec to version "
"2024.12.0 or later to enable this functionality."
)

from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper

return AsyncFileSystemWrapper(fs, asynchronous=True)
Expand Down
16 changes: 15 additions & 1 deletion tests/test_store/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_open_fsmap_file_raises(tmp_path: pathlib.Path) -> None:
fsspec = pytest.importorskip("fsspec.implementations.local")
fs = fsspec.LocalFileSystem(auto_mkdir=False)
mapper = fs.get_mapper(tmp_path)
with pytest.raises(ValueError, match="LocalFilesystem .*"):
with pytest.raises(FileNotFoundError, match="No such file or directory: .*"):
array_roundtrip(mapper)


Expand Down Expand Up @@ -426,3 +426,17 @@ async def test_delete_dir_wrapped_filesystem(tmp_path: Path) -> None:
assert await store.exists("foo-bar/zarr.json")
assert not await store.exists("foo/zarr.json")
assert not await store.exists("foo/c/0")


@pytest.mark.skipif(
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
reason="No AsyncFileSystemWrapper",
)
async def test_with_read_only_auto_mkdir(tmp_path: Path) -> None:
"""
Test that creating a read-only copy of a store backed by the local file system does not error
if auto_mkdir is False.
"""

store_w = FsspecStore.from_url(f"file://{tmp_path}", storage_options={"auto_mkdir": False})
_ = store_w.with_read_only()