You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "jiayuasu (via GitHub)" <gi...@apache.org> on 2026/07/14 05:07:25 UTC
[PR] feat(python/sedonadb): add DataFrame.unnest [sedona-db]
jiayuasu opened a new pull request, #1050:
URL: https://github.com/apache/sedona-db/pull/1050
Adds `DataFrame.unnest(*columns)`, which expands list/array column(s) so each element becomes its own row — the relational form of pandas/GeoPandas `explode()`.
```python
df.unnest("vals") # [10, 20, 30] -> 3 rows, other columns repeated
df.unnest("a", "b") # multiple columns unnested in parallel (position-by-position)
df.unnest("parts") # ST_Dump(geom) -> one row per part (spatial explode)
```
## Design
- Thin wrapper over DataFusion's `DataFrame::unnest_columns`; mirrors the existing `drop_columns` binding.
- **Engine-neutral naming** (`unnest`, matching Ibis / DuckDB SQL `UNNEST`) rather than the pandas-flavored `explode`, consistent with the relational DataFrame surface.
- Clear errors: no arguments -> `ValueError`; non-str argument -> `TypeError`; unknown column -> `SedonaError` ("No field named …"); a raw geometry (Binary) column -> `SedonaError` (unnest a multi-geometry via `ST_Dump` first).
## Tests
New `tests/expr/test_dataframe_unnest.py` (8 tests): list-to-rows expansion, parallel multi-column unnest, the `ST_Dump` + `unnest` multi-geometry explode, laziness, and the four error paths. Plus a doctest on the method.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(python/sedonadb): add DataFrame.unnest [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu merged PR #1050:
URL: https://github.com/apache/sedona-db/pull/1050
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(python/sedonadb): add DataFrame.unnest [sedona-db]
Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #1050:
URL: https://github.com/apache/sedona-db/pull/1050#discussion_r3576234399
##########
python/sedonadb/python/sedonadb/dataframe.py:
##########
@@ -504,6 +504,49 @@ def drop(self, *cols: str) -> "DataFrame":
return DataFrame(self._ctx, self._impl.drop_columns(list(cols)))
+ def unnest(self, *columns: str) -> "DataFrame":
+ """Expand list/array column(s) so each element becomes its own row.
+
+ This is the relational form of `pandas`/`GeoPandas` `explode()`: for
+ each input row, a list-typed column is expanded to one output row per
+ element, with the other columns repeated. When several columns are
+ given, they are unnested in parallel (position by position).
+
+ A common spatial use is flattening a multi-geometry: `ST_Dump(geom)`
+ returns a list of parts, and `unnest()` turns each part into its own
+ row.
+
Review Comment:
It would be nice to show an example of this (I think you have to select() or mutate() with `df.geometry.geo.dump()` and then unnest and then `col("geometry")["parts"]` to get the struct field).
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(python/sedonadb): add DataFrame.unnest [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1050:
URL: https://github.com/apache/sedona-db/pull/1050#discussion_r3582773146
##########
python/sedonadb/python/sedonadb/dataframe.py:
##########
@@ -504,6 +504,49 @@ def drop(self, *cols: str) -> "DataFrame":
return DataFrame(self._ctx, self._impl.drop_columns(list(cols)))
+ def unnest(self, *columns: str) -> "DataFrame":
+ """Expand list/array column(s) so each element becomes its own row.
+
+ This is the relational form of `pandas`/`GeoPandas` `explode()`: for
+ each input row, a list-typed column is expanded to one output row per
+ element, with the other columns repeated. When several columns are
+ given, they are unnested in parallel (position by position).
+
+ A common spatial use is flattening a multi-geometry: `ST_Dump(geom)`
+ returns a list of parts, and `unnest()` turns each part into its own
+ row.
+
Review Comment:
Good call — added an example. It walks through `ST_Dump` → `unnest` → pulling the geometry out of the `{path, geom}` struct (`dumped["dump"]["geom"]`), rendering the two points. Used the `.geo.dump()` accessor as you suggested.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org