Skip to content

Validate element-type selection when reading Zarr stores - #1253

Open
kayoderaheem wants to merge 2 commits into
scverse:mainfrom
kayoderaheem:fix/read-zarr-selection-1172
Open

kayoderaheem wants to merge 2 commits into
scverse:mainfrom
kayoderaheem:fix/read-zarr-selection-1172

Conversation

@kayoderaheem

Copy link
Copy Markdown

Fixes #1172.

Invalid selection names currently pass through silently, which can return an empty SpatialData object or load only part of the requested data.

This change validates selection names before opening the Zarr store and raises a descriptive ValueError for invalid names or a bare string. It also narrows the type annotations for both reader entry points and corrects the SpatialData.read() documentation to use "tables".

Existing behavior is preserved for None, empty tuples, duplicate valid names, and valid element types absent from the store.

Testing: the new regression tests produced 8 failures and 14 passes before the fix, and all 22 passed afterward. Together with the existing read/write and partial-read suites, 177 tests passed, with 545 warnings. Ruff lint, formatting, and whitespace checks also passed. The full project suite and Python-version matrix were not run.

The issue discussion suggests narrower typing and optionally an assertion. This implementation uses ValueError so validation remains active under optimized Python. Feedback on that choice is welcome.

@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.66%. Comparing base (65dc73e) to head (26e4ba9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1253      +/-   ##
==========================================
+ Coverage   91.40%   91.66%   +0.25%     
==========================================
  Files          53       53              
  Lines        8381     8384       +3     
==========================================
+ Hits         7661     7685      +24     
+ Misses        720      699      -21     
Files with missing lines Coverage Δ
src/spatialdata/__main__.py 76.19% <100.00%> (+76.19%) ⬆️
src/spatialdata/_core/spatialdata.py 93.84% <ø> (+0.48%) ⬆️
src/spatialdata/_io/io_zarr.py 88.70% <100.00%> (+0.27%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Invalid "selection" values in "read_zarr()" should raise an error

1 participant