Skip to content

Commit 2b68ec1

Browse files
authored
Fix bug in v2 zarr parser which interprets empty dimension list as truthy (#936)
* fix empty list truthy bug * Fix scalar variable parsing in ZarrParser Fix `ZarrParser` issue with scalar variable parsing from v2 native zarr stores.
1 parent bdc1a3a commit 2b68ec1

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

docs/releases.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
- Fix `ZarrParser` not using the store-relative path when the zarr store is nested inside the object store root
4141
([#913](https://github.com/zarr-developers/VirtualiZarr/pull/913)).
4242
By [Tom Nicholas](https://github.com/TomNicholas).
43+
- Fix `ZarrParser` not correctly parsing scalar variables from v2 native zarr stores ([#936](https://github.com/zarr-developers/VirtualiZarr/pull/936)).
44+
By [Julius Buseceke](https://github.com/jbusecke)
4345

4446
### Documentation
4547

virtualizarr/parsers/zarr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _convert_v2_to_v3_dict(metadata: ArrayV2Metadata) -> dict:
348348
# to V3's dimension_names, so we do it manually.
349349
attrs = cast(dict, v3_dict.get("attributes", {}))
350350
dim_names = attrs.get("_ARRAY_DIMENSIONS")
351-
if v3_dict.get("dimension_names") is None and dim_names:
351+
if v3_dict.get("dimension_names") is None and dim_names is not None:
352352
v3_dict["dimension_names"] = dim_names
353353

354354
# _ARRAY_DIMENSIONS is a V2 convention that gets promoted to dimension_names in V3,

virtualizarr/tests/test_parsers/test_zarr.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ def test_v2_metadata_with_dimensions():
243243
assert metadata.dimension_names == ("x", "y")
244244

245245

246+
@requires_v2_migration
247+
def test_v2_metadata_with_scalar_dimensions():
248+
"""Test V2 metadata conversion for scalar array with _ARRAY_DIMENSIONS=[]."""
249+
store = zarr.storage.MemoryStore()
250+
array = zarr.create(shape=(), chunks=(), dtype="int64", store=store, zarr_format=2)
251+
array.attrs["_ARRAY_DIMENSIONS"] = []
252+
253+
metadata = metadata_as_v3(zarr.open(store, mode="r").metadata)
254+
assert metadata.dimension_names == ()
255+
256+
246257
def test_v3_metadata_separator_normalized():
247258
"""Test that metadata_as_v3 normalizes V3 chunk_key_encoding separator to '.'."""
248259
store = zarr.storage.MemoryStore()

0 commit comments

Comments
 (0)