Skip to content

rasterize: reject NaN bounds from empty geometries (#2065)#2071

Merged
brendancol merged 2 commits into
mainfrom
issue-2065
May 18, 2026
Merged

rasterize: reject NaN bounds from empty geometries (#2065)#2071
brendancol merged 2 commits into
mainfrom
issue-2065

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Empty geometries used to leak NaN into the inferred output extent. Three related fixes:

  • _parse_input returns None for inferred bounds when GeoPandas total_bounds is non-finite (empty GeoDataFrame).
  • The inferred-bounds path filters out geometries whose bbox is non-finite, so a single empty Polygon no longer poisons the extent computed from a mixed list.
  • Explicit non-finite check on the resolved bounds with a clear ValueError, before the existing xmin < xmax test.

Before: rasterize([(Polygon(), 99), (box(0,0,1,1), 1)], width=2, height=2) returned a (2, 2) raster with x = [nan, nan], y = [nan, nan], and no burn.

Closes #2065

Test plan

  • New tests in TestValidation: mixed empty + real geometry produces finite coords and correct burn; only-empty input raises; empty GeoDataFrame raises; explicit NaN bounds raises.
  • Full rasterize suite: 160 passed, 2 skipped.

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 18, 2026
Three related fixes:

1. _parse_input returns None for inferred bounds when GeoPandas
   total_bounds is non-finite (empty GeoDataFrame).
2. Inferred-bounds calculation filters out geometries whose bbox is
   non-finite so a single empty Polygon doesn't poison the extent.
3. Explicit non-finite check on resolved bounds with a clear error
   message before the existing xmin<xmax test.

Before: an empty geometry mixed with a real one produced a raster
with x = [nan, nan], y = [nan, nan], and no burn.

Closes #2065
Address review nit: extend coverage to empty MultiPolygon. The
existing fix in _geometry_bboxes / inferred-bounds filtering catches
it (shapely returns the same (nan,nan,nan,nan) for an empty
MultiPolygon as for an empty Polygon), but a dedicated test locks
that in.
@brendancol brendancol merged commit 9a7ffca into main May 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rasterize: empty geometries leak NaN bounds into inferred extent

1 participant