Skip to content

Conversation

@m-albert
Copy link
Contributor

@m-albert m-albert commented Jul 1, 2025

This PR implements a fix for #947.

Problem summary: spatialdata.transform transforms each of the scales of a multi-scale image and it can happen that (especially lower resolution) scales result in shape 0. One one hand it doesn't make sense to keep zero shape scales, on the other this leads to an error later on when the scale factors of the resulting image are extracted.

Fix proposed in this PR: scales resulting in zero shape are discarded, similarly to the postprocessing of bounding_box_query:

def _process_data_tree_query_result(query_result: DataTree) -> DataTree | None:
d = {}
for k, data_tree in query_result.items():
v = data_tree.values()
assert len(v) == 1
xdata = v.__iter__().__next__()
if 0 in xdata.shape:
if k == "scale0":
return None
else:
d[k] = xdata

In the case of 'scale0' resulting in zero shape, the PR proposes to raise an error.

Happy to work on any review points!

@codecov
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.21%. Comparing base (2794fb0) to head (6903802).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #948   +/-   ##
=======================================
  Coverage   92.20%   92.21%           
=======================================
  Files          49       49           
  Lines        7572     7576    +4     
=======================================
+ Hits         6982     6986    +4     
  Misses        590      590           
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/transform.py 91.37% <100.00%> (+0.15%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings January 5, 2026 16:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #947 by implementing logic to discard scales that result in zero shape when transforming multi-scale images, similar to the existing pattern in bounding_box_query. When scale0 (highest resolution) results in zero shape, an error is raised instead.

  • Adds zero-shape detection and filtering logic in the DataTree transform function
  • Raises a ValueError when scale0 (highest resolution) results in zero shape
  • Adds a test to verify zero-shape scale handling

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/spatialdata/_core/operations/transform.py Adds logic to detect and skip scales with zero shape during transformation, with special error handling for scale0
tests/core/operations/test_transform.py Adds test for zero-shape scale handling and imports Image2DModel

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

LucaMarconato and others added 4 commits January 5, 2026 18:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@LucaMarconato
Copy link
Member

LucaMarconato commented Jan 5, 2026

Thanks for catching this and making a fix! I made only minor changes. Waiting until it's green and then merging.

@LucaMarconato LucaMarconato merged commit b4ea1a9 into scverse:main Jan 5, 2026
9 checks passed
@m-albert
Copy link
Contributor Author

m-albert commented Jan 6, 2026

Thanks Luca!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants