Skip to content

Commit 563e99d

Browse files
committed
Wrap sync fs for xarray.to_zarr
1 parent f360fc6 commit 563e99d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/zarr/storage/fsspec.py

Lines changed: 4 additions & 0 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.implementations.asyn_wrapper import AsyncFileSystemWrapper
7+
68
from zarr.abc.store import ByteRangeRequest, Store
79
from zarr.storage.common import _dereference_path
810

@@ -166,6 +168,8 @@ def from_url(
166168
opts = {"asynchronous": True, **opts}
167169

168170
fs, path = url_to_fs(url, **opts)
171+
if not fs.async_impl:
172+
fs = AsyncFileSystemWrapper(fs)
169173

170174
# fsspec is not consistent about removing the scheme from the path, so check and strip it here
171175
# https://github.com/fsspec/filesystem_spec/issues/1722

tests/test_store/test_fsspec.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88
from botocore.session import Session
9+
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
910

1011
import zarr.api.asynchronous
1112
from zarr.core.buffer import Buffer, cpu, default_buffer_prototype
@@ -214,3 +215,19 @@ async def test_empty_nonexistent_path(self, store_kwargs) -> None:
214215
store_kwargs["path"] += "/abc"
215216
store = await self.store_cls.open(**store_kwargs)
216217
assert await store.is_empty("")
218+
219+
220+
def test_wrap_sync_filesystem():
221+
"""The local fs is not async so we should expect it to be wrapped automatically"""
222+
store = FsspecStore.from_url("local://test/path")
223+
224+
assert isinstance(store.fs, AsyncFileSystemWrapper)
225+
assert store.fs.async_impl
226+
227+
228+
def test_no_wrap_async_filesystem():
229+
"""An async fs should not be wrapped automatically; fsspec's https filesystem is such an fs"""
230+
store = FsspecStore.from_url("https://test/path")
231+
232+
assert not isinstance(store.fs, AsyncFileSystemWrapper)
233+
assert store.fs.async_impl

0 commit comments

Comments
 (0)