Skip to content

fix #382: handle 'layers' stored as h5py.Dataset in read_stereo_h5ad#430

Closed
cursor[bot] wants to merge 1 commit intomainfrom
cursorissue-fix-automation-ca60
Closed

fix #382: handle 'layers' stored as h5py.Dataset in read_stereo_h5ad#430
cursor[bot] wants to merge 1 commit intomainfrom
cursorissue-fix-automation-ca60

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor bot commented Mar 25, 2026

Summary

When reading a stereopy-flavored h5ad file via read_h5ad(flavor='stereopy'), the layers key may be stored as an h5py.Dataset instead of an h5py.Group. The existing code unconditionally called .keys() on f['layers'], which raises AttributeError: 'Dataset' object has no attribute 'keys'.

Changes

  • stereo/io/reader.py: Added an isinstance(f[k], h5py.Group) check before iterating layer keys. When layers is a Dataset, it is read directly via h5ad.read_dataset().
  • tests/test_read_stereo_h5ad_layers.py: Added regression tests verifying both Dataset and Group scenarios work correctly.

Closes #382

Open in Web View Automation 

When reading a stereopy-flavored h5ad file, the 'layers' key may be stored
as an h5py.Dataset instead of an h5py.Group. Previously, the code
unconditionally called .keys() on f['layers'], which raises AttributeError
on Dataset objects. Now we check isinstance(f[k], h5py.Group) first and
handle Dataset fallback by reading it directly.

Co-authored-by: wanruiwen-genomics-cn <wanruiwen-genomics-cn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read_h5ad meets error: 'Dataset' object has no attribute 'keys'

2 participants