Skip to content

feat: support raster labels up to 2^53-1 (old limit: 2^16-1) - #1167

Merged
jan-glx merged 7 commits into
scverse:mainfrom
stanbot8:fix/987-raster-label-dtype
Nov 23, 2026
Merged

jan-glx merged 7 commits into
scverse:mainfrom
stanbot8:fix/987-raster-label-dtype

Conversation

@stanbot8

Copy link
Copy Markdown
Contributor

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 91.71%. Comparing base (e949102) to head (2d6ece8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1167      +/-   ##
==========================================
+ Coverage   91.58%   91.71%   +0.12%     
==========================================
  Files          53       53              
  Lines        8400     8399       -1     
==========================================
+ Hits         7693     7703      +10     
+ Misses        707      696      -11     
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/rasterize.py 93.55% <100.00%> (+2.12%) ⬆️

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

@stanbot8
stanbot8 force-pushed the fix/987-raster-label-dtype branch from 72250aa to 6bb3786 Compare October 1, 2026 19:46
@ajkswamy

Copy link
Copy Markdown
Collaborator

related PR: #1287

@jan-glx jan-glx self-assigned this Nov 13, 2026
@jan-glx

jan-glx commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for pushing this, @stanbot8 , can you try 2**53 + 1, I think this might fail silently.

@jan-glx

jan-glx commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Pushed xfail tests showing that labels of 2**53 or higher are silently rounded, including when overlapping labels are summed (CI: 3 xfailed). The cause is that datashader aggregates in float64.

@jan-glx

jan-glx commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Pushed a fix on top: labels ≥ 2**53 (incl. overlapping labels summed to ≥ 2**53) now raise a ValueError instead of being silently rounded; the xfail test stays as a marker for the root cause. CI green. @ajkswamy ready for review for the bugfix release.

@jan-glx
jan-glx enabled auto-merge (squash) November 19, 2026 09:29
@jan-glx jan-glx changed the title fix: support raster labels above uint16 feat: support raster labels up to 2^53-1 (old limit: 2^16-1) Nov 23, 2026
@jan-glx
jan-glx disabled auto-merge November 23, 2026 16:06
@jan-glx
jan-glx merged commit bc1aecc into scverse:main Nov 23, 2026
18 checks passed
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.

exceeding rasterize's maximum label index

3 participants