Skip to content

Commit 1a6eb06

Browse files
authored
Merge pull request #374 from martindurant/xarray_test
Xarray test via dask threads
2 parents d95a8b4 + 4d2a149 commit 1a6eb06

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

s3fs/core.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ async def _call_s3(self, method, *akwarglist, **kwargs):
204204
**kwargs)
205205
for i in range(self.retries):
206206
try:
207-
return await method(**additional_kwargs)
207+
out = await method(**additional_kwargs)
208+
locals().pop("err", None) # break cycle following retry
209+
return out
208210
except S3_RETRYABLE_ERRORS as e:
209211
logger.debug("Retryable error: %s" % e)
210212
err = e
@@ -484,7 +486,7 @@ async def _find(self, path, maxdepth=None, withdirs=None, detail=False):
484486
async def _mkdir(self, path, acl="", create_parents=True, **kwargs):
485487
path = self._strip_protocol(path).rstrip('/')
486488
bucket, key, _ = self.split_path(path)
487-
if not key or (create_parents and not self.exists(bucket)):
489+
if not key or (create_parents and not await self._exists(bucket)):
488490
if acl and acl not in buck_acls:
489491
raise ValueError('ACL not in %s', buck_acls)
490492
try:
@@ -595,6 +597,12 @@ async def _exists(self, path):
595597
elif self.dircache.get(bucket, False):
596598
return True
597599
else:
600+
try:
601+
if self._ls_from_cache(bucket):
602+
return True
603+
except FileNotFoundError:
604+
# might still be a bucket we can access but don't own
605+
pass
598606
try:
599607
await self.s3.list_objects_v2(MaxKeys=1, Bucket=bucket, **self.req_kw)
600608
return True

s3fs/tests/test_s3fs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,20 @@ def test_repeat_exists(s3):
16411641
assert s3.exists(fn)
16421642

16431643

1644+
def test_with_xzarr(s3):
1645+
da = pytest.importorskip("dask.array")
1646+
xr = pytest.importorskip("xarray")
1647+
name = "sample"
1648+
1649+
nana = xr.DataArray(da.random.random((1024, 1024, 10, 9, 1)))
1650+
1651+
s3_path = f"{test_bucket_name}/{name}"
1652+
s3store = s3.get_mapper(s3_path)
1653+
1654+
s3.ls("")
1655+
nana.to_dataset().to_zarr(store=s3store, mode="w", consolidated=True, compute=True)
1656+
1657+
16441658
@pytest.mark.skipif(sys.version_info < (3, 7), reason="no asyncio.run in py36")
16451659
def test_async_close():
16461660
async def _():

0 commit comments

Comments
 (0)