Skip to content

Commit 1f36344

Browse files
committed
Fix the conflict between zarr storage directory and a regular directory
1 parent 0d5ee75 commit 1f36344

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

wsidata/io/_wsi.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ def open_wsi(
114114
# We also support write all backed file to a directory
115115
backed_file_p = Path(store)
116116
if backed_file_p.is_dir():
117-
zarr_name = Path(wsi).with_suffix(".zarr").name
118-
store = backed_file_p / zarr_name
117+
if is_zarr_dir(backed_file_p):
118+
store = backed_file_p
119+
else:
120+
zarr_name = Path(wsi).with_suffix(".zarr").name
121+
store = backed_file_p / zarr_name
119122
else:
120123
store = backed_file_p
121124

@@ -274,3 +277,22 @@ def _agg_wsi(f, feature_key, tile_key, agg_key, error="raise"):
274277
raise e
275278
else:
276279
return None
280+
281+
282+
def is_zarr_dir(path):
283+
"""
284+
Detect if the given directory is a Zarr storage using the Zarr library.
285+
286+
Parameters:
287+
path (str): The path to the directory.
288+
289+
Returns:
290+
bool: True if the directory is a Zarr storage, False otherwise.
291+
"""
292+
import zarr
293+
294+
try:
295+
zarr.open_group(path, mode="r")
296+
return True
297+
except Exception:
298+
return False

0 commit comments

Comments
 (0)