Repository navigation
Fix DataFolder.read_dataset for raw 2D datasets without axes - #241
Merged
Merged
Conversation
write_dataset() stores a raw DataSet (no axis set) at the HDF5 file root instead of in a group named after the dataset. read_dataset() only looked for a child group with that name, so it raised FileNotFoundError for a file it had just written. It now falls back to the file root when the root attributes identify it as the requested raw dataset, for both the h5py and h5netcdf backends. Fixes #240 Co-authored-by: heevasti <87366176+heevasti@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DataFolder.write_dataset()stores a rawDataSet(data without axes, e.g. plain 2D data) at the root of the HDF5 file, marking it via theQMI_Dataset_name(and related) file attributes.DataFolder.read_dataset()only looked for a child group named after the dataset, so for raw datasets it raisedFileNotFoundErroreven though the file it had just written does contain the data.This fixes the regression by making
read_dataset()fall back to reading the file root when no child group with the given name exists but the root attributes identify it as that raw dataset — for both theh5pyandh5netcdfbackends.qmi/data/datastore.py:DataFolder.read_dataset()now checksf.attrs[QMI_Dataset_name]as a fallback before raisingFileNotFoundError.tests/data/test_datastore.py: addedtest_29_read_raw_2d_dataset_without_axes_in_hdf5andtest_29b_read_raw_2d_dataset_without_axes_in_hdf5_h5netcdf_backend, covering the write/read round trip for a 2D rawDataSetwith both backends.CHANGELOG.md: documented the fix under "Fixed" in the Unreleased section.Fixes #240
Test plan
uv run coverage run --branch -m unittest discover --start-directory="tests" --pattern="test_*.py"— all 3185 tests pass (including the 2 new tests)uv run ruff check --fix --output-format pylint— cleanuv run mypy qmi examples --namespace-package --explicit-package-bases— clean (pre-existing unrelated errors inexamples/only)FileNotFoundError, for both backends🤖 Generated with Claude Code