Add coregister=True to .xrs.rasterize accessor (#3492)#3493
Merged
Conversation
brendancol
commented
Jun 25, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Add coregister=True to .xrs.rasterize accessor
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
dask_geopandasgap:is_geodataframerecognizes plain geopandas only, so adask_geopandasframe withcoregister=Trueraises "requires a GeoDataFrame", even though standalonerasterize._parse_inputaccepts one. This mirrors the interpolation accessor (#3481) on purpose. Addressed by a code comment so the gap is intentional and discoverable; reprojecting a dask_geopandas frame under coregister can be a follow-up.
Nits (optional improvements)
- The missing-CRS error message said
(attrs['crs']), but_like_crsalso readscrs_wkt, aspatial_refcoord, orrio.crs. Reworded to "(its detected raster CRS)".
What looks good
- Using
_like_crs(obj)for the reprojection target (rather than onlyattrs['crs']) matches how rasterize's owncheck_crsfinds the template CRS, so the reprojected frame compares equal and the default guard passes cleanly. coregisteris accessor-only; the standalonerasterize()signature is untouched, the same split #3481 used for interpolation.- Shared
_rasterize_on_accessorhelper keeps the DataArray and Dataset accessors in sync.
Checklist
- Reprojection path defers to the unchanged rasterize (algorithm unaffected)
- Backend dispatch unchanged; coregister runs before dispatch (numpy/dask verified, cupy inherits)
- NaN/fill handled by rasterize as before
- Edge cases covered: missing CRS, mismatch, non-GeoDataFrame, Dataset accessor
- No premature materialization; dask template stays lazy until output
- Benchmark not needed (input-parsing glue, no new kernel)
- README feature matrix not applicable (no new function, no backend change)
- Docstrings present on both accessor methods and the helper
brendancol
commented
Jun 25, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
Follow-up review (after 3a6ae84)
Re-read the full changed files at head. The two findings from the first pass are resolved:
- Suggestion (dask_geopandas gap) — fixed: added a code comment in
_rasterize_on_accessormarking the geopandas-only gate as intentional parity with #3481, with the dask_geopandas case noted as a follow-up. - Nit (error message) — fixed: the missing-CRS message now reads "(its detected raster CRS)" instead of "(attrs['crs'])", matching
_like_crs's broader detection.
No new issues. Tests still green (8 passed locally). Nothing blocking.
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 #3492
Gives
.xrs.rasterizethe samecoregisterflag the interpolation accessors got in #3481.coregister=False(default) keeps current behavior: a GeoDataFrame whose CRS differs from the caller raster still raises through rasterize's owncheck_crs.coregister=Truereprojects a GeoDataFrame's geometries from their CRS into the caller raster's CRS (viaGeoDataFrame.to_crs) before rasterizing, so the burn lands on the caller grid. It needs a CRS on both the geometries (.crs) and the caller (detected the same waycheck_crsdetects the template CRS), and raises a clear error otherwise._rasterize_on_accessorhelper that mirrors_interp_on_accessor.rasterize()function is untouched;coregisteris accessor-only, the same split Accept GeoDataFrames in interpolation + expose on .xrs accessor with coregister #3481 used.Backends
Input-parsing only: the coregister branch runs before backend dispatch and just reprojects the GeoDataFrame, then hands off to the unchanged
rasterize. numpy and dask+numpy verified directly; cupy / dask+cupy inherit the unchanged rasterize dispatch.Test plan
test_accessor.py/test_rasterize.py/test_interpolate_vector.pypass unchanged