Skip to content

Commit 1e66c40

Browse files
d-v-bmaxrjones
andauthored
Remove breaking check about auto_mkdir for FSSpecStore (#3193) (#3203)
* Remove breaking check from _make_async * Update expected error * Change import structure to protect against AttributeError * changelog * add test to ensure that we can create a read-only copy of the store with auto_mkdir=False * only test if the async wrapper is available --------- (cherry picked from commit 5a24487) Co-authored-by: Max Jones <14077947+maxrjones@users.noreply.github.com>
1 parent d01eced commit 1e66c40

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

changes/3193.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Removed an unnecessary check from ``_fsspec._make_async`` that would raise an exception when
2+
creating a read-only store backed by a local file system with ``auto_mkdir`` set to ``False``.

src/zarr/storage/_fsspec.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,15 @@ def _make_async(fs: AbstractFileSystem) -> AsyncFileSystem:
5656
fs_dict["asynchronous"] = True
5757
return fsspec.AbstractFileSystem.from_json(json.dumps(fs_dict))
5858

59-
# Wrap sync filesystems with the async wrapper
60-
if type(fs) is fsspec.implementations.local.LocalFileSystem and not fs.auto_mkdir:
61-
raise ValueError(
62-
f"LocalFilesystem {fs} was created with auto_mkdir=False but Zarr requires the filesystem to automatically create directories"
63-
)
6459
if fsspec_version < parse_version("2024.12.0"):
6560
raise ImportError(
6661
f"The filesystem '{fs}' is synchronous, and the required "
6762
"AsyncFileSystemWrapper is not available. Upgrade fsspec to version "
6863
"2024.12.0 or later to enable this functionality."
6964
)
65+
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
7066

71-
return fsspec.implementations.asyn_wrapper.AsyncFileSystemWrapper(fs, asynchronous=True)
67+
return AsyncFileSystemWrapper(fs, asynchronous=True)
7268

7369

7470
class FsspecStore(Store):

tests/test_store/test_fsspec.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def test_open_fsmap_file_raises(tmp_path: pathlib.Path) -> None:
365365
fsspec = pytest.importorskip("fsspec.implementations.local")
366366
fs = fsspec.LocalFileSystem(auto_mkdir=False)
367367
mapper = fs.get_mapper(tmp_path)
368-
with pytest.raises(ValueError, match="LocalFilesystem .*"):
368+
with pytest.raises(FileNotFoundError, match="No such file or directory: .*"):
369369
array_roundtrip(mapper)
370370

371371

@@ -426,3 +426,17 @@ async def test_delete_dir_wrapped_filesystem(tmp_path: Path) -> None:
426426
assert await store.exists("foo-bar/zarr.json")
427427
assert not await store.exists("foo/zarr.json")
428428
assert not await store.exists("foo/c/0")
429+
430+
431+
@pytest.mark.skipif(
432+
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
433+
reason="No AsyncFileSystemWrapper",
434+
)
435+
async def test_with_read_only_auto_mkdir(tmp_path: Path) -> None:
436+
"""
437+
Test that creating a read-only copy of a store backed by the local file system does not error
438+
if auto_mkdir is False.
439+
"""
440+
441+
store_w = FsspecStore.from_url(f"file://{tmp_path}", storage_options={"auto_mkdir": False})
442+
_ = store_w.with_read_only()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy