Skip to content

Respect value_key when aggregating image channels - #1252

Open
Qinzi27 wants to merge 1 commit into
scverse:mainfrom
Qinzi27:codex/fix-274-image-value-key
Open

Qinzi27 wants to merge 1 commit into
scverse:mainfrom
Qinzi27:codex/fix-274-image-value-key

Conversation

@Qinzi27

@Qinzi27 Qinzi27 commented Sep 17, 2026

Copy link
Copy Markdown

Image aggregation currently ignores value_key: requesting "CD3" still aggregates every image channel. This change selects the requested channels before computing zonal statistics, so only those channels appear in the result.

Channel order follows the request, while value_key=None preserves aggregation of all channels. The public signature, statistics, and channel_<name>_<statistic> output names remain unchanged. Empty requests, duplicate requests, unknown channels, and non-unique image channel names raise ValueError when explicitly selecting channels.

Regression tests cover single and multiscale images, hand-calculated mean/sum/count values, channel order, invalid requests, input preservation, region metadata, and the SpatialData.aggregate() wrapper with zone_ids.

Validation on Python 3.12.9:

  • Before the fix: 29 of the 35 new cases failed; the 6 all-channel controls passed.
  • After the fix: pytest tests/core/operations/test_aggregations.py -q — 85 passed, 6 skipped.
  • Ruff 0.16.4 formatting and lint passed for the two changed files.
  • mypy passed for all 58 source files; git diff --check passed.

These are local checks; the full test suite and remote CI matrix have not been run. The separate int8/uint8 table-validation issue in #1229 is outside this change; the regression tests use int32 labels.

Fixes #274.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.49%. Comparing base (65dc73e) to head (02340aa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1252      +/-   ##
==========================================
+ Coverage   91.40%   91.49%   +0.08%     
==========================================
  Files          53       53              
  Lines        8381     8394      +13     
==========================================
+ Hits         7661     7680      +19     
+ Misses        720      714       -6     
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/aggregate.py 92.62% <100.00%> (+3.41%) ⬆️
🚀 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.

value_key is ignored in aggregate() for images

1 participant