Repository navigation
fix: relabel_sequential() for unsigned integer dtypes - #1287
Open
MMatinGerami wants to merge 1 commit into
Open
MMatinGerami wants to merge 1 commit into
MMatinGerami wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1287 +/- ##
=======================================
Coverage 91.43% 91.43%
=======================================
Files 53 53
Lines 8395 8395
=======================================
Hits 7676 7676
Misses 719 719
🚀 New features to boost your workflow:
|
MMatinGerami
force-pushed
the
fix/relabel-sequential-unsigned
branch
from
October 29, 2026 02:26
1e70493 to
8cb7f58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1215
Problem
relabel_sequential()builds its lookup table withWith NumPy 2 (NEP 50) the Python int
-1can no longer be cast to an unsigned dtype, so the function raisesOverflowError: Python integer -1 out of bounds for uint16for everyuint8/uint16/uint32/uint64input. Segmentation masks are almost always unsigned, andmap_raster(relabel=True)points users to this function.Fix
The fill value is never read: every label present in
arris overwritten bynew_labeling[unique_labels] = da.arange(...), andnew_labeling[arr]only reads those positions. So the table is now created withda.zeros(max_label + 1, dtype=arr.dtype), which is valid for every integer dtype. Behaviour for signed dtypes is unchanged (same output, same dtype).Tests
test_relabel_sequential_dtypesis parametrized overuint8,uint16,uint32,uint64,int8,int32,int64and checks both the values and that the output dtype equals the input dtype. Onmainthe four unsigned cases fail with theOverflowError; with this change all 11-k relabeltests intests/core/operations/test_map.pypass (numpy 2.5.4). A changelog entry is added under Unreleased / Fixed.LLM usage
An LLM coding assistant helped find and draft this fix.