Skip to content

Add ManifestStore support for empty chunks. #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions virtualizarr/manifests/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def with_validation(
"""

# note: we can't just use `__init__` or a dataclass' `__post_init__` because we need `fs_root` to be an optional kwarg

path = validate_and_normalize_path_to_uri(path, fs_root=fs_root)
if path != "":
path = validate_and_normalize_path_to_uri(path, fs_root=fs_root)
validate_byte_range(offset=offset, length=length)
return ChunkEntry(path=path, offset=offset, length=length)

Expand Down
2 changes: 2 additions & 0 deletions virtualizarr/manifests/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ async def get(
key, marr.metadata.chunk_key_encoding.separator
)
path = manifest._paths[*chunk_indexes]
if path == "":
return None
offset = manifest._offsets[*chunk_indexes]
length = manifest._lengths[*chunk_indexes]
# Get the configured object store instance that matches the path
Expand Down
35 changes: 35 additions & 0 deletions virtualizarr/tests/test_manifests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ def s3_store(minio_bucket):
)


@pytest.fixture()
def empty_memory_store():
import obstore as obs

store = obs.store.MemoryStore()
prefix = get_store_prefix("")
chunk_dict = {
"0.0": {"path": "", "offset": 0, "length": 4},
}
manifest = ChunkManifest(entries=chunk_dict)
codecs = [{"configuration": {"endian": "little"}, "name": "bytes"}]
array_metadata = create_v3_array_metadata(
shape=(1, 1),
chunk_shape=(1, 1),
data_type=np.dtype("int32"),
codecs=codecs,
chunk_key_encoding={"name": "default", "separator": "."},
fill_value=0,
)
manifest_array = ManifestArray(metadata=array_metadata, chunkmanifest=manifest)
manifest_group = ManifestGroup(arrays={"foo": manifest_array})
registry = ObjectStoreRegistry({prefix: store})
return ManifestStore(store_registry=registry, group=manifest_group)


@requires_obstore
class TestManifestStore:
def test_manifest_store_properties(self, local_store):
Expand All @@ -135,6 +160,16 @@ def test_manifest_store_properties(self, local_store):
assert not local_store.supports_writes
assert not local_store.supports_partial_writes

@pytest.mark.asyncio
@pytest.mark.parametrize(
"manifest_store",
["empty_memory_store"],
)
async def test_get_empty_chunk(self, manifest_store, request):
store = request.getfixturevalue(manifest_store)
observed = await store.get("foo/c/0.0", prototype=default_buffer_prototype())
assert observed is None

@pytest.mark.asyncio
@pytest.mark.parametrize(
"manifest_store",
Expand Down
Loading