Skip to content

Commit

Permalink
Keep boolean enums as unit8 unless JSON compatibility is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Aug 2, 2024
1 parent d96956a commit ea0ffa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hdf5_hl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function process_data(data: Uint8Array, metadata: Metadata, json_compatible: boo
output_data = process_data(data, base_metadata, json_compatible);
// Following the convention of h5py, treat all enum datasets where the
// enum members are ["FALSE", "TRUE"] as boolean arrays
if (isH5PYBooleanEnum(metadata.enum_type as EnumTypeMetadata)) {
if (json_compatible && isH5PYBooleanEnum(metadata.enum_type as EnumTypeMetadata)) {
if (isIterable(output_data)) {
output_data = [...output_data].map((x) => !!x);
}
Expand Down
5 changes: 5 additions & 0 deletions test/bool_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ async function bool_test() {

assert.deepEqual(
f.get('bool').value,
new Int8Array([ 0, 1, 1, 0 ])
);

assert.deepEqual(
f.get('bool').json_value,
[ false, true, true, false ]
);

Expand Down

0 comments on commit ea0ffa9

Please sign in to comment.