Skip to content

Commit ed11018

Browse files
committed
Make async instances from sync fsmap objects
1 parent e792e01 commit ed11018

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/zarr/storage/_fsspec.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import warnings
44
from typing import TYPE_CHECKING, Any
55

6+
from fsspec import AbstractFileSystem
7+
68
from zarr.abc.store import (
79
ByteRequest,
810
OffsetByteRequest,
@@ -16,7 +18,6 @@
1618
if TYPE_CHECKING:
1719
from collections.abc import AsyncIterator, Iterable
1820

19-
from fsspec import AbstractFileSystem
2021
from fsspec.asyn import AsyncFileSystem
2122
from fsspec.mapping import FSMap
2223

@@ -43,9 +44,9 @@ def _make_async(fs: AbstractFileSystem) -> AsyncFileSystem:
4344
if fs.async_impl and fs.asynchronous:
4445
return fs
4546
if fs.async_impl:
46-
raise NotImplementedError(
47-
f"The filesystem '{fs}' is synchronous and wrapping synchronous filesystems using from_mapper has not been implemented. See https://github.com/zarr-developers/zarr-python/issues/2706 for more details."
48-
)
47+
fs_dict = fs.to_dict()
48+
fs_dict["asynchronous"] = True
49+
return AbstractFileSystem.from_dict(fs_dict)
4950
try:
5051
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
5152

@@ -187,7 +188,7 @@ def from_mapper(
187188
-------
188189
FsspecStore
189190
"""
190-
if not fs_map.fs.asynchronous:
191+
if not fs_map.fs.async_impl or not fs_map.fs.asynchronous:
191192
fs_map.fs = _make_async(fs_map.fs)
192193
return cls(
193194
fs=fs_map.fs,

tests/test_store/test_fsspec.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ async def test_basic() -> None:
106106
assert out[0].to_bytes() == data[1:]
107107

108108

109-
def test_open_s3map() -> None:
110-
s3_filesystem = s3fs.S3FileSystem(asynchronous=True, endpoint_url=endpoint_url, anon=False)
109+
@pytest.mark.parametrize("asynchronous", [True, False])
110+
def test_open_s3map(asynchronous: bool) -> None:
111+
s3_filesystem = s3fs.S3FileSystem(
112+
asynchronous=asynchronous, endpoint_url=endpoint_url, anon=False
113+
)
111114
mapper = s3_filesystem.get_mapper(f"s3://{test_bucket_name}/map/foo/")
112115
arr = zarr.open(store=mapper, mode="w", shape=(3, 3))
113116
assert isinstance(arr, Array)

0 commit comments

Comments
 (0)