Skip to content
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

Fix errors on Infinity and on slices with integers for HSDS #645

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Changes from all commits
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
15 changes: 13 additions & 2 deletions src/h5web/providers/hsds/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class HsdsApi extends ProviderApi {
} catch {
// https://github.com/HDFGroup/hsds/issues/87
try {
return JSON.parse(data.replaceAll('NaN', '"NaN"'));
return JSON.parse(data.replaceAll(/(NaN|-?Infinity)/gu, '"$&"'));
axelboc marked this conversation as resolved.
Show resolved Hide resolved
} catch {
return data;
}
Expand Down Expand Up @@ -104,7 +104,18 @@ export class HsdsApi extends ProviderApi {
const entity = await this.getEntity(path);
assertHsdsDataset(entity);

return this.fetchValue(entity.id, selection);
const value = await this.fetchValue(entity.id, selection);

// https://github.com/HDFGroup/hsds/issues/88
// HSDS does not reduce the number of dimensions when selecting indices
// This is an issue when trying to slice nD arrays
// Therefore the dimension reduction is done "manually" here with a flat
const numberIndices = selection.match(/\d+/gu)?.length;
if (!numberIndices) {
return value;
}

return (value as unknown[]).flat(numberIndices);
axelboc marked this conversation as resolved.
Show resolved Hide resolved
}

private async fetchRootId(): Promise<HsdsId> {
Expand Down