Fix NaN pixels producing spurious polygons in numpy/dask backends#1194
Merged
brendancol merged 1 commit intomasterfrom Apr 14, 2026
Merged
Fix NaN pixels producing spurious polygons in numpy/dask backends#1194brendancol merged 1 commit intomasterfrom
brendancol merged 1 commit intomasterfrom
Conversation
) The numpy backend for polygonize() passed float arrays straight to _calculate_regions without masking NaN pixels. Since NaN != NaN, each NaN pixel became its own isolated region and emitted a spurious single-pixel polygon with a NaN value. The CuPy backend already handled this correctly by building a valid-pixel mask via ~cp.isnan(data). Apply the same approach in _polygonize_numpy: detect float dtype and fold ~np.isnan(values) into the mask before region calculation. The dask backend inherits this fix since it calls _polygonize_numpy per chunk.
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 #1190
Summary
polygonize()didn't mask NaN pixels in float rasters. SinceNaN != NaN, each NaN pixel became its own isolated region and emitted a single-pixel polygon with a NaN value.~cp.isnan(data). This applies the same masking in_polygonize_numpy, which the dask backend inherits.Test plan
test_polygonize_nan_pixels_excluded-- 2x2 float raster with NaN, both 4- and 8-connectivitytest_polygonize_nan_pixels_excluded_dask-- 3x3 float raster with NaN, dask chunked