-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ensure KeyError raised for zarr datasets missing dim names #10025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4a11b6b
442a747
35af1ec
256e7ff
8cda2aa
c985350
ac6e468
6024346
ac7f796
fd57789
c1a1c70
8e1d4c1
8ef2412
9980dda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,6 +375,11 @@ def _get_zarr_dims_and_attrs(zarr_obj, dimension_key, try_nczarr): | |
pass | ||
else: | ||
attributes = dict(zarr_obj.attrs) | ||
if len(zarr_obj.shape) != len(dimensions): | ||
raise KeyError( | ||
"Zarr object is missing the `dimension_names` metadata which is " | ||
"required for xarray to determine variable dimensions." | ||
) | ||
return dimensions, attributes | ||
|
||
# Zarr arrays do not have dimensions. To get around this problem, we add | ||
|
@@ -393,7 +398,13 @@ def _get_zarr_dims_and_attrs(zarr_obj, dimension_key, try_nczarr): | |
|
||
# NCZarr defines dimensions through metadata in .zarray | ||
zarray_path = os.path.join(zarr_obj.path, ".zarray") | ||
zarray = json.loads(zarr_obj.store[zarray_path]) | ||
if _zarr_v3(): | ||
import asyncio | ||
|
||
zarray_str = asyncio.run(zarr_obj.store.get(zarray_path)).to_bytes() | ||
else: | ||
zarray_str = zarr_obj.store.get(zarray_path) | ||
zarray = json.loads(zarray_str) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would you find it useful if zarr let you do this with a single function? because we could totally add that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've not needed to access the 'zarray' info before, so that wouldn't make a big difference to me. But it seems nczarr does use it and I was just trying to get this existing code to work with zarr-python 3. |
||
try: | ||
# NCZarr uses Fully Qualified Names | ||
dimensions = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's no check previously guaranteeing that this is zarr_format=2, an additional check for zarray_paths ending with
zarr.json
will likely be needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the first try/except block in this function is intended to ensure we have zarr_format=2 here:
https://github.com/oliverwm1/xarray/blob/c1a1c70310f256a1125b08f089e5688075f89d78/xarray/backends/zarr.py#L368-L375