fix #382: handle 'layers' as h5py.Dataset in read_stereo_h5ad#447
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix #382: handle 'layers' as h5py.Dataset in read_stereo_h5ad#447cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
In _read_stereo_h5ad_from_group(), the 'layers' key handler unconditionally called f[k].keys(), which fails when 'layers' is stored as an h5py.Dataset rather than an h5py.Group. Added isinstance(f[k], h5py.Group) check before iterating sub-keys, falling back to h5ad.read_dataset() for the Dataset case. This matches the existing pattern used for 'exp_matrix' handling in the same function. Added tests covering both Group and Dataset code paths. Co-authored-by: wanruiwen-genomics-cn <wanruiwen-genomics-cn@users.noreply.github.com>
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
In
_read_stereo_h5ad_from_group(), thelayerskey handler unconditionally calledf[k].keys()on line 318 ofstereo/io/reader.py. When a Stereopy-format H5AD file storeslayersas anh5py.Datasetrather than anh5py.Group, this raisesAttributeError: 'Dataset' object has no attribute 'keys'.The root cause is a missing type guard — the same pattern is already correctly handled for
exp_matrix(lines 303–307) andexp_matrix@raw(lines 327–330) in the same function.Changes
stereo/io/reader.py: Added anisinstance(f[k], h5py.Group)check before iterating overf['layers']sub-keys. Iflayersis aGroup, the existing per-key iteration is preserved. If it's aDataset, it is read directly viah5ad.read_dataset().tests/test_read_h5ad_layers.py: Added 3 pytest tests verifying both the Group and Dataset code paths, plus a regression test confirming the originalAttributeErrorno longer occurs.Verification
exp_matrixClassification
layersas a flat Dataset)Closes #382