Skip to content

Commit

Permalink
don't allow empty chunks if no chunk grid shape given
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Oct 18, 2024
1 parent b61fb17 commit bd12745
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions virtualizarr/manifests/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def __init__(self, entries: dict, shape: tuple[int, ...] | None = None) -> None:
"0.1.1": {"path": "s3://bucket/foo.nc", "offset": 400, "length": 100},
}
"""
if shape is None and not entries:
raise ValueError("need a chunk grid shape if no chunks given")

# TODO do some input validation here first?
validate_chunk_keys(entries.keys())
Expand Down
8 changes: 8 additions & 0 deletions virtualizarr/tests/test_manifests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def test_create_manifest(self):
manifest = ChunkManifest(entries=chunks)
assert manifest.dict() == chunks

chunks = {}
manifest = ChunkManifest(entries=chunks, shape=(2, 2))
assert manifest.dict() == chunks

def test_create_manifest_empty_missing_shape(self):
with pytest.raises(ValueError, match="chunk grid shape if no chunks"):
ChunkManifest(entries={})

def test_invalid_chunk_entries(self):
chunks = {
"0.0.0": {"path": "s3://bucket/foo.nc"},
Expand Down

0 comments on commit bd12745

Please sign in to comment.