Skip to content

fix: support raster labels above uint16#1167

Open
stanbot8 wants to merge 1 commit into
scverse:mainfrom
stanbot8:fix/987-raster-label-dtype
Open

fix: support raster labels above uint16#1167
stanbot8 wants to merge 1 commit into
scverse:mainfrom
stanbot8:fix/987-raster-label-dtype

Conversation

@stanbot8

Copy link
Copy Markdown

2 implementations exist. This implementation uses 1 canvas and only removes the label-count limit. The other implementation adds opt-in output tiles after this commit to limit output memory. Compare the limitations.

Summary

In issue 987, rasterize(..., return_regions_as_labels=True) rejects more than 65,535 labels. Select the output dtype from the maximum label. Closes #987.

Design

Use the existing _get_uint_dtype() helper, as proposed in the maintainer direction. Small outputs remain uint16. Larger outputs use uint32 or uint64 only when required.

The implementation changes src/spatialdata/_core/operations/rasterize.py.

Limitations

This implementation uses 1 canvas. It removes the label-count limit, but it does not bound output memory.

Tests

1 boundary test rasterizes 65,536 indexed points. It preserves label 65,536 in uint32 output.

The focused rasterization suites pass with 28 tests. The complete suite passes with 1,365 tests, 7 skips, and 1 expected failure. An isolated installed wheel passes the same boundary case.

The test is in tests/core/operations/test_rasterize.py.

Commands
uv run pytest tests/core/operations/test_rasterize.py::test_rasterize_points_selects_label_dtype -q

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.47%. Comparing base (eb4fb3d) to head (72250aa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1167      +/-   ##
==========================================
+ Coverage   92.44%   92.47%   +0.03%     
==========================================
  Files          51       51              
  Lines        7820     7817       -3     
==========================================
  Hits         7229     7229              
+ Misses        591      588       -3     
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/rasterize.py 90.84% <100.00%> (+0.24%) ⬆️

... and 1 file with indirect coverage changes

🚀 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.

exceeding rasterize's maximum label index

1 participant