Skip to content

Commit

Permalink
Support reading metadata of committed datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Aug 26, 2024
1 parent 53d7d0f commit d8c1b2f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion h5grove/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ def metadata(self, depth: int = 1):
)


class DatatypeContent(ResolvedEntityContent[h5py.Datatype]):
kind = "datatype"

def metadata(self, depth=None):
"""
:returns: {"attributes": AttributeMetadata, "kind": str, "name": str, "type": TypeMetadata}
"""
return sorted_dict(
("type", get_type_metadata(self._h5py_entity.id)),
*super().metadata().items(),
)


def create_content(
h5file: h5py.File,
path: Optional[str],
Expand Down Expand Up @@ -267,7 +280,7 @@ def create_content(
return GroupContent(path, entity, h5file)

if isinstance(entity, h5py.Datatype):
return ResolvedEntityContent(path, entity)
return DatatypeContent(path, entity)

raise TypeError(f"h5py entity {type(entity)} not supported")

Expand Down
17 changes: 17 additions & 0 deletions test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ def test_data_on_opaque(self, server):
retrieved_data = np.void(response.content)
assert np.array_equal(retrieved_data, data)

def test_meta_on_datatype(self, server):
"""Test /meta/ endpoint on a committed datatype"""
filename = "test.h5"

with h5py.File(server.served_directory / filename, mode="w") as h5file:
h5file["committed_type"] = np.dtype("<f8")

response = server.get(f"/meta/?file={filename}&path=/committed_type")
content = decode_response(response)

assert content == {
"attributes": [],
"kind": "datatype",
"name": "committed_type",
"type": {"class": 1, "dtype": "<f8", "size": 8, "order": 0},
}

def test_meta_on_chunked_compressed_dataset(self, server):
"""Test /meta/ endpoint on a chunked and compressed dataset"""
filename = "test.h5"
Expand Down

0 comments on commit d8c1b2f

Please sign in to comment.