Skip to content

Commit

Permalink
Support fetching boolean data as binary
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Aug 29, 2024
1 parent 55f9fdf commit d8cd78e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion h5grove/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _sanitize_dtype(dtype: np.dtype) -> np.dtype:
:raises ValueError: If trying to sanitize a non-numeric numpy dtype
"""
if dtype.kind not in ("f", "i", "u"):
if dtype.kind not in ("f", "i", "u", "b"):
raise ValueError(f"Unsupported numpy dtype `{dtype}`. Expected numeric dtype.")

# Convert to little endian
Expand Down
21 changes: 21 additions & 0 deletions test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ def test_data_on_slice_with_format_and_flatten(self, server, format_arg):

assert retrieved_data - data[100, 0] < 1e-8

def test_data_on_bool(self, server):
"""Test /data/ endpoint on boolean dataset with format=bin"""
tested_h5entity_path = "/bool"
data = np.array([True, False, True, True])

filename = "test.h5"
with h5py.File(server.served_directory / filename, mode="w") as h5file:
dset = h5file.create_dataset(tested_h5entity_path, data=data)
dtype = dset.dtype
shape = dset.shape

response = server.get(
f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'format': 'bin'})}"
)

content_type = response.find_header_value("content-type")
assert content_type == "application/octet-stream"

retrieved_data = decode_array_response(response, "bin", dtype.str, shape)
assert np.array_equal(retrieved_data, data)

def test_data_on_opaque(self, server):
"""Test /data/ endpoint on opaque dataset with format=bin"""
tested_h5entity_path = "/opaque"
Expand Down

0 comments on commit d8cd78e

Please sign in to comment.