feat(python/sedonadb-geopandas): add dissolve - #1246
Open
jiayuasu wants to merge 3 commits into
Open
Conversation
Group rows on one or more key columns and union each group's geometry via collect_agg plus unary_union — ST_Union_Agg only initializes for polygonal input (apache#1093) — with the union in a separate projection since a scalar wrapped around an aggregate is not a valid aggregate expression. dropna matches GeoPandas by treating IEEE NaN in floating keys as missing alongside SQL null, with dictionary encoding unwrapped; an all-null geometry group coalesces to an empty geometry collection re-typed back to geometry. Documented differences: group keys stay ordinary columns (no index), first is unordered and does not skip missing values, an empty frame without keys yields one row, mixed 2D/3D groups raise, and grouping is observed-only. Temporal group keys are rejected for now: pandas missing values arrive from numpy-backed frames as a sentinel tick that must group as missing, which needs the dedicated temporal handling that arrives as its own change.
jiayuasu
marked this pull request as draft
September 9, 2026 06:57
…ther in both modes Missing-key handling only ran with dropna=True, so with dropna=False a SQL NULL and an IEEE NaN in the same floating-point key column formed two missing groups where pandas forms one. Normalize NaN to null before grouping, in both modes, so the two representations group as a single missing key; the dropna filter then only needs the null check.
…olumn named self Build the NaN-to-null gate in the key's own float type so a Float32 key is not widened by the addition, and pass every mutate() column as a positional alias rather than a keyword: a column named 'self' collided with mutate's own first parameter in assignment, reprojection, and dissolve alike.
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.
What changes
Second slice of the series that started with #1195 (column assignment). This one adds
GeoDataFrame.dissolve()to the experimentalsedonadb-geopandaspackage: group rows on one or more key columns (or on nothing, to dissolve everything into one row) and union each group's geometry.ST_Collect_Aggfollowed by aST_UnaryUnionin a separate projection.ST_Union_Aggonly initializes for polygonal input (ST_Union_Agg returns NULL for point inputs #1093), so a group of points or lines would dissolve to NULL; collect-then-union is geometry-general and yields the geometry types GeoPandas yields. The union sits in its own projection because a scalar function wrapped around an aggregate is not a valid aggregate expression. A group whose geometries are all null coalesces to an empty geometry collection re-typed back to geometry, matching GeoPandas.dropnamodes, so a column holding both representations forms one missing group rather than two (anddropna=Truedrops both). Floating-ness is decided from the Arrow type, dictionary encoding unwrapped, rather than from the type's string form, so alist<double>column is not mistaken for somethingisnan()can be applied to.by=[]raises (unlikeby=None), unknown keys raiseKeyError, and onlyaggfunc="first"is supported for now with an error that points at the SedonaDBDataFrameAPI for anything else.INT64_MINtick, which must group (anddropna) as missing rather than as a value; that handling arrives with the temporal follow-up.Documented differences from GeoPandas (also in the README): group keys stay ordinary columns rather than becoming the index;
"first"is an unordered aggregate that does not skip missing values; dissolving an empty frame without keys yields one row rather than zero; a group mixing 2D and 3D geometries raises rather than being promoted to 3D; and grouping is observed-only for categorical keys, since the category domain does not survive a relational aggregation.Testing
18 new tests (136 in the package), including a corpus over every geometry type, GeoPandas parity for
dropna, nested-float and dictionary-encoded keys, the all-null group, and the categorical case; run with warnings promoted to errors against both a source-built current main and the released sedonadb 0.4.1 in a clean environment (pandas 2 and 3). Ruff lint/format clean.