@@ -180,14 +180,30 @@ def _find(names: Sequence[str], base: Path) -> Optional[Path]:
180180def _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
193209def _first_available (root , candidates : Sequence [str ]) -> Optional [np .ndarray ]:
0 commit comments