Skip to content

Commit

Permalink
Ensure _ARRAY_DIMENSIONS get dropped from attrs (#153)
Browse files Browse the repository at this point in the history
* regression test that _ARRAY_DIMENSIONS is dropped from the variable.attrs

* ensure _ARRAY_DIMENSIONS is dropped

* give attrs tests their own test class

* release notes
  • Loading branch information
TomNicholas authored Jun 23, 2024
1 parent 7fca86b commit a7a5d4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Deprecations
Bug fixes
~~~~~~~~~

- Ensure that `_ARRAY_DIMENSIONS` are dropped from variable `.attrs`. (:issue:`150`, :pull:`152`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
7 changes: 7 additions & 0 deletions virtualizarr/tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ def test_concat_dim_coords_along_existing_dim(self):
assert result.data.zarray.zarr_format == zarray.zarr_format


class TestOpenVirtualDatasetAttrs:
def test_drop_array_dimensions(self, netcdf4_file):
# regression test for GH issue #150
vds = open_virtual_dataset(netcdf4_file, indexes={})
assert "_ARRAY_DIMENSIONS" not in vds["air"].attrs


class TestOpenVirtualDatasetIndexes:
def test_no_indexes(self, netcdf4_file):
vds = open_virtual_dataset(netcdf4_file, indexes={})
Expand Down
6 changes: 5 additions & 1 deletion virtualizarr/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ def variable_from_kerchunk_refs(

arr_refs = kerchunk.extract_array_refs(refs, var_name)
chunk_dict, zarray, zattrs = kerchunk.parse_array_refs(arr_refs)

manifest = ChunkManifest._from_kerchunk_chunk_dict(chunk_dict)
dims = zattrs["_ARRAY_DIMENSIONS"]

# we want to remove the _ARRAY_DIMENSIONS from the final variables' .attrs
dims = zattrs.pop("_ARRAY_DIMENSIONS")

varr = virtual_array_class(zarray=zarray, chunkmanifest=manifest)

return xr.Variable(data=varr, dims=dims, attrs=zattrs)
Expand Down

0 comments on commit a7a5d4c

Please sign in to comment.