Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion virtualizarr/manifests/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
expand_dims,
)
from virtualizarr.manifests.manifest import ChunkManifest
from virtualizarr.utils import determine_chunk_grid_shape


class ManifestArray:
Expand Down Expand Up @@ -64,7 +65,16 @@ def __init__(
f"chunkmanifest arg must be of type ChunkManifest or dict, but got type {type(chunkmanifest)}"
)

# TODO check that the metadata shape and chunkmanifest shape are consistent with one another
# check that the metadata shape and chunkmanifest shape are consistent with one another
metadata_chunk_grid_shape = determine_chunk_grid_shape(
shape=metadata.shape, chunks=metadata.chunks
)
if _chunkmanifest.shape_chunk_grid != metadata_chunk_grid_shape:
raise ValueError(
"Set of virtual chunk keys in manifest do not match shape of chunk grid implied by array metadata. \n"
f"Keys in chunkmanifest imply a chunk grid shape of {_chunkmanifest.shape_chunk_grid} but the metadata contains shape={_metadata.shape} and chunks={_metadata.chunks} which imply a chunk grid shape of {metadata_chunk_grid_shape}"
)

# TODO also cover the special case of scalar arrays

self._metadata = _metadata
Expand Down
15 changes: 15 additions & 0 deletions virtualizarr/tests/test_manifests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def test_manifest_array_dict_v3_metadata(self, array_v3_metadata):
assert marr.size == 5 * 2 * 20
assert marr.ndim == 3

def test_consistency_checks(self, array_v3_metadata):
# create a manifest with only one chunk
chunks_dict = {
"0": {"path": "s3://bucket/foo.nc", "offset": 100, "length": 100},
}
manifest = ChunkManifest(entries=chunks_dict)

# but array metadata implying there should be two chunks
chunks = (1,)
shape = (2,)
metadata = array_v3_metadata(shape=shape, chunks=chunks)

with pytest.raises(ValueError, match="do not match shape of chunk grid"):
ManifestArray(metadata=metadata, chunkmanifest=manifest)


class TestResultType:
def test_idempotent(self, manifest_array):
Expand Down
Loading