Skip to content

Commit

Permalink
Merge pull request #76 from axelboc/no-bool-cast
Browse files Browse the repository at this point in the history
Don't convert boolean enums unless JSON compatibility is requested
  • Loading branch information
bmaranville authored Aug 6, 2024
2 parents d96956a + 88bd71b commit dc3f592
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Changelog
## v0.7.6
### Changed
- Retrieve `value` of boolean dataset as `Int8Array` instead of plain JS boolean array. To retrieve a plain JS boolean array, use `json_value` instead:

```ts
// v0.7.5 and earlier
bool_dset.value; // -> [false, true]
bool_dset.json_value; // -> [false, true]

// v0.7.6 onwards
bool_dset.value; // -> Int8Array(2) [0, 1]
bool_dset.json_value; // -> [false, true]
```
## v0.7.5 2024-06-03
### Added
- added `virtual_sources?: { file_name: string, dset_name: string }` to `Dataset.metadata` when dataset is virtual.
Expand Down
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 dc3f592

Please sign in to comment.