rasterize: reject NaN bounds from empty geometries (#2065)#2071
Merged
Conversation
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.
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.
Summary
Empty geometries used to leak NaN into the inferred output extent. Three related fixes:
_parse_inputreturnsNonefor inferred bounds when GeoPandastotal_boundsis non-finite (empty GeoDataFrame).Polygonno longer poisons the extent computed from a mixed list.ValueError, before the existingxmin < xmaxtest.Before:
rasterize([(Polygon(), 99), (box(0,0,1,1), 1)], width=2, height=2)returned a (2, 2) raster withx = [nan, nan],y = [nan, nan], and no burn.Closes #2065
Test plan
TestValidation: mixed empty + real geometry produces finite coords and correct burn; only-empty input raises; empty GeoDataFrame raises; explicit NaN bounds raises.