Skip to content

Commit

Permalink
also allow writing empty chunk manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Oct 17, 2024
1 parent 8e5752c commit ac700a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions virtualizarr/manifests/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ def dict(self) -> ChunkDict: # type: ignore[override]
Entries whose path is an empty string will be interpreted as missing chunks and omitted from the dictionary.
"""

if len(self) == 0:
return cast(ChunkDict, {})

coord_vectors = np.mgrid[
tuple(slice(None, length) for length in self.shape_chunk_grid)
]
Expand Down
29 changes: 29 additions & 0 deletions virtualizarr/tests/test_writers/test_kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ def test_accessor_to_kerchunk_dict(self):
result_ds_refs = ds.virtualize.to_kerchunk(format="dict")
assert result_ds_refs == expected_ds_refs

def test_accessor_to_kerchunk_dict_empty(self):
manifest = ChunkManifest.empty()
arr = ManifestArray(
chunkmanifest=manifest,
zarray=dict(
shape=(2, 3),
dtype=np.dtype("<i8"),
chunks=(2, 3),
compressor=None,
filters=None,
fill_value=np.nan,
order="C",
),
)
ds = Dataset({"a": (["x", "y"], arr)})

expected_ds_refs = {
"version": 1,
"refs": {
".zgroup": '{"zarr_format":2}',
".zattrs": "{}",
"a/.zarray": '{"shape":[2,3],"chunks":[2,3],"dtype":"<i8","fill_value":null,"order":"C","compressor":null,"filters":null,"zarr_format":2}',
"a/.zattrs": '{"_ARRAY_DIMENSIONS":["x","y"]}',
},
}

result_ds_refs = ds.virtualize.to_kerchunk(format="dict")
assert result_ds_refs == expected_ds_refs

def test_accessor_to_kerchunk_json(self, tmp_path):
manifest = ChunkManifest(
entries={"0.0": dict(path="test.nc", offset=6144, length=48)}
Expand Down

0 comments on commit ac700a9

Please sign in to comment.