jiayuasu opened a new pull request, #1142: URL: https://github.com/apache/sedona-db/pull/1142
Extends the experimental `sedonadb-geopandas` package (#1052) with the operations a real pipeline needs: a spatial join, a dissolve, column assignment, and arithmetic on columns. ```python gdf = sgpd.from_geopandas(points) gdf["density"] = gdf["pop"] / gdf["area"] # assign a computed column joined = gdf.sjoin(regions, predicate="within") # spatial join zones = joined.dissolve(by="region") # group and union geometry ``` ## What is added - **`sjoin(other, how, predicate, lsuffix, rsuffix, distance)`** — `how` of `inner`, `left`, or `right`, over the `intersects`, `within`, `contains`, `touches`, `crosses`, `overlaps`, `covers`, `covered_by`, and `dwithin` predicates. The predicate reads left-relative-to-right as in GeoPandas. The result carries exactly one geometry column — the left frame's, or the right frame's for `how="right"`, matching which side GeoPandas keeps — and column names occurring on both sides get the `lsuffix`/`rsuffix` treatment. - **`dissolve(by, aggfunc="first")`** — unions each group's geometry via `ST_Union_Agg` and carries the remaining columns. `by=None` dissolves everything into one row. - **`__setitem__`** — `gdf["x"] = ...` from a `Series` of the same frame, a SedonaDB expression, or a scalar to broadcast. - **Arithmetic on `Series`** — `+`, `-`, `*`, `/`, unary `-`, and the reflected forms. - **`Series.expr`** — the underlying expression, as an escape hatch for anything the wrapper does not cover (`series.expr.funcs.st_point(other.expr)`), assignable back onto a frame. ## Two semantics worth review attention **`/` follows pandas, not SQL.** The engine truncates when dividing integers, so `v / 2` over an integer column would return floored values where pandas returns `0.5`, `1.5`, and so on. Since the point of this package is that GeoPandas code keeps working, the numerator is cast to double first. `//` is deliberately *not* implemented rather than mapped onto SQL division, which truncates toward zero where Python floors — a subtly wrong operator seemed worse than a missing one. **Assignment rebinds the frame.** The underlying frame is immutable, so `gdf["x"] = ...` replaces the frame this object points at. A `Series` captured before that assignment therefore belongs to the previous frame, and combining it with a later read raises rather than silently mixing two frames. The error message says so explicitly. ## Deviations from GeoPandas, all documented in the README - `sjoin` produces no `index_left`/`index_right` column, and `dissolve` leaves the group keys as ordinary columns rather than moving them into the index. Both follow from there being no row index. - Columns cannot be combined across two frames; without row alignment that would be a silent wrong answer, so it raises and suggests joining first. ## Verification Checked against GeoPandas rather than only for self-consistency: - `sjoin` column shapes match exactly for all three `how` values (after dropping the `index_*` columns), as do the active geometry column and the row count. - `sjoin` row pairings match. - `dissolve` areas and first-aggregated column values match (`[7.0, 4.0]` and `[1, 3]`). - Arithmetic matches, including the reflected forms. 46 tests pass locally and in a clean virtual environment installing `sedonadb` from the nightly index — the environment shape that caught the missing dependency in #1134. `ruff format` and `ruff check` are clean. ## Deferred The `GeoSeries` accessor batch (`geom_type`, `x`/`y`, `bounds`, `envelope`, `boundary`, `to_wkt`, and friends) is left for a follow-up. One compatibility wrinkle to settle there: `ST_GeometryType` returns `ST_Polygon` where GeoPandas' `geom_type` returns `Polygon`, so that mapping needs a decision rather than a quick pass-through. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
