diff --git a/changes/3193.bugfix.rst b/changes/3193.bugfix.rst new file mode 100644 index 0000000000..a6e387c10c --- /dev/null +++ b/changes/3193.bugfix.rst @@ -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``. \ No newline at end of file diff --git a/src/zarr/storage/_fsspec.py b/src/zarr/storage/_fsspec.py index 0d854b0561..a1b05a7630 100644 --- a/src/zarr/storage/_fsspec.py +++ b/src/zarr/storage/_fsspec.py @@ -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) diff --git a/tests/test_store/test_fsspec.py b/tests/test_store/test_fsspec.py index 1a989525e3..026b25f8fc 100644 --- a/tests/test_store/test_fsspec.py +++ b/tests/test_store/test_fsspec.py @@ -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) @@ -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()