Skip to content

Commit 75615b3

Browse files
committed
a
1 parent 58a7e1b commit 75615b3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies = [
2020
"scipy>=1.10",
2121
"tqdm>=4.66",
2222
"zarr>=2.16",
23+
"requests>=2.31",
2324
]
2425

2526
[tool.setuptools]

src/pyXenium/io/partial_xenium_loader.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,30 @@ def _find(names: Sequence[str], base: Path) -> Optional[Path]:
180180
def _open_zarr(path: Path | str):
181181
if zarr is None: # pragma: no cover
182182
raise ImportError("zarr is required to read *.zarr or *.zarr.zip")
183+
183184
pstr = str(path)
184185
if _is_url(pstr):
185186
path = _fetch_to_temp(pstr)
186187
pstr = str(path)
188+
189+
# 打开 *.zarr.zip:只读 ZipStore + 只读 group
187190
if pstr.endswith(".zip"):
188-
store = ZipStore(str(path), mode="r")
189-
return zarr.group(store=store)
190-
return zarr.open_group(str(path), mode="r")
191+
store = ZipStore(pstr, mode="r")
192+
# Zarr v3 优先
193+
if hasattr(zarr, "open_group"):
194+
return zarr.open_group(store=store, mode="r")
195+
# 兼容旧版 Zarr v2
196+
if hasattr(zarr, "open"):
197+
return zarr.open(store, mode="r")
198+
# 最后兜底(极旧环境)
199+
return zarr.group(store=store, mode="r")
200+
201+
# 打开目录/文件路径:优先 v3 API,其次 v2,再兜底
202+
if hasattr(zarr, "open_group"):
203+
return zarr.open_group(pstr, mode="r")
204+
if hasattr(zarr, "open"):
205+
return zarr.open(pstr, mode="r")
206+
return zarr.group(store=pstr, mode="r")
191207

192208

193209
def _first_available(root, candidates: Sequence[str]) -> Optional[np.ndarray]:

0 commit comments

Comments
 (0)