polygonize: add return type annotation (#2148)#2152
Merged
brendancol merged 1 commit intoMay 20, 2026
Conversation
The public polygonize() entry point was the only vector/raster conversion function in xrspatial without a return type annotation on its signature. Sibling functions sieve, contours, rasterize, and clip_polygon all declare one. Static type checkers, IDE hover help, and Sphinx autodoc had nothing to display. Adds a Union return annotation covering all five return_type modes (numpy tuple, awkward tuple, geopandas GeoDataFrame, spatialpandas GeoDataFrame, geojson dict). Optional-dependency types are imported under TYPE_CHECKING and referenced as forward strings so module import is unaffected. Also expands the docstring Returns section to enumerate the per-return_type shapes explicitly instead of the previous one-line "in a format determined by return_type" reference. Found by /sweep-api-consistency 2026-05-19. State CSV updated with the pass record, including the cross-module connectivity-vs- neighborhood naming drift between polygonize and sieve (out of scope for the polygonize-scoped sweep branch; deprecation shim belongs in sieve.py) and the cross-cutting raster-vs-agg drift (library-wide, not filed per-module per sweep template).
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
Unionreturn annotation topolygonize()covering all fivereturn_typemodes (numpy tuple, awkward tuple, geopandasGeoDataFrame, spatialpandasGeoDataFrame, geojsondict). Optional-dependency types live underTYPE_CHECKINGand are referenced as forward strings, so importingxrspatial.polygonizestill works without geopandas/spatialpandas/awkward installed.Returnssection to spell out each per-return_typeshape instead of the previous one-line "in a format determined byreturn_type" deferral..claude/sweep-api-consistency-state.csvwith the 2026-05-19 polygonize pass record.Closes #2148.
Why
polygonizewas the only public vector/raster conversion function in xrspatial without a return type annotation. Siblingssieve,contours,rasterize,clip_polygonall declare one. Static type checkers, IDE hover help, and Sphinx autodoc all sawpolygonize(...)with an unspecified return type while the docstring documented the per-mode shapes.Found by
/sweep-api-consistency2026-05-19.Out of scope (documented in sweep state)
polygonizeusesconnectivity(int 4|8) whilesieveusesneighborhood(int 4|8) for the identical rook/queen pixel-connectivity concept. Industry convention (GDAL, rasterio.features.sieve) favoursconnectivity; the deprecation shim belongs insieve.py, not inpolygonize, so it is out of scope for this polygonize-scoped sweep branch.raster(polygonize/sieve/clip_polygon) vsagg(contours and many older modules) for the input DataArray. Library-wide drift, not filed per-module per sweep template.Test plan
pytest xrspatial/tests/test_polygonize.py -x -q-> 114 passed, 13 skipped (unchanged)inspect.signature(polygonize).return_annotationresolves to the expectedUnionreturn_typemodes