Repository navigation
Conversation
In `xarray/backends/zarr.py`, `_normalize_zip_fsspec_store` detects read-only `zip://` URLs and `FsspecStore` instances backed by a zip filesystem (unwrapping `AsyncFileSystemWrapper` when present) and wraps the store in a cached `WrapperStore` subclass from `_zip_missing_key_store_cls`. The wrapper catches `KeyError` in `get`, `get_partial_values`, and `get_partial` (when present on `WrapperStore`), returning `None` if `self._store.exists(key)` is false and re-raising otherwise, while preserving `with_read_only` and updating `close_store_on_close` in `_get_open_params` to close newly created stores. A regression test `test_load_dataarray_fsspec_zip_coordinates` is added to `xarray/tests/backends/test_zarr.py`, and a release note is added to `doc/whats-new.rst`. Fixes pydata#10950
5 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Opening a Zarr archive through an
fsspeczip URL or zip filesystem fails with aKeyErrorwhen reading coordinates or variables whose chunks contain only the fill value (for example, a coordinate value of0). Loading the same archive from a local directory or directly throughzarr.storage.ZipStoresucceeds. Zarr omits chunks that match the fill value and expects missing store keys to returnNone, whereasfsspec'sZipFileSystemraisesKeyErrorwhen an archive member is absent.Because
xarrayeagerly reads 1D coordinate arrays to build default indexes when opening a dataset or data array,zarr.storage.FsspecStoresurfaces thatKeyErrorduring open.In
xarray/backends/zarr.py,_normalize_zip_fsspec_storedetects read-onlyzip://URLs andFsspecStoreinstances backed by a zip filesystem (unwrappingAsyncFileSystemWrapperwhen present) and wraps the store in a cachedWrapperStoresubclass from_zip_missing_key_store_cls. The wrapper catchesKeyErroringet,get_partial_values, andget_partial(when present onWrapperStore), returningNoneifself._store.exists(key)is false and re-raising otherwise, while preservingwith_read_onlyand updatingclose_store_on_closein_get_open_paramsto close newly created stores. A regression testtest_load_dataarray_fsspec_zip_coordinatesis added toxarray/tests/backends/test_zarr.py, and a release note is added todoc/whats-new.rst.Running
pytest -q xarray/tests/backends/test_zarr.pyfailed during collection withModuleNotFoundError: No module named 'numpy'.The documentation redirect check comparing historical
doc/pages againstgit ls-files docanddoc/conf.pycompleted with no missing pages reported.A run with the xarray _iter_zarr_groups change reverted gave no clear result, so no test is shown to catch this bug.
The changed test xarray/tests/backends/test_zarr.py did not run here: the numpy module is not installed.
Closes #10950
Checklist
whats-new.rstapi.rstAI Disclosure
I have tested any AI-generated content in my PR.
No result recorded for the xarray _iter_zarr_groups change backs this box.
I take responsibility for any AI-generated content in my PR.
Tools: {e.g., Claude, Codex, GitHub Copilot, ChatGPT, etc.}
AI disclosure
AI was used for assistance.