Copilot commented on code in PR #3159:
URL: https://github.com/apache/sedona/pull/3159#discussion_r3643665202


##########
python/sedona/spark/geopandas/geoseries.py:
##########
@@ -658,17 +668,14 @@ def _query_geometry_column(
         index_spark_columns = []
         index_fields = []
         if not is_aggr:
-            # We always select NATURAL_ORDER_COLUMN_NAME, to avoid having to 
regenerate it in the result.
-            # We always select SPARK_DEFAULT_INDEX_NAME, to retain series 
index info.
-
-            exprs.append(scol_for(df, SPARK_DEFAULT_INDEX_NAME))
-            exprs.append(scol_for(df, NATURAL_ORDER_COLUMN_NAME))
-
-            index_spark_columns = [scol_for(df, SPARK_DEFAULT_INDEX_NAME)]
-            index_fields = [self._internal.index_fields[0]]
+            # Preserve every index level and the natural order in the result.
+            index_spark_columns = [
+                scol_for(df, name) for name in 
self._internal.index_spark_column_names
+            ]

Review Comment:
   `_query_geometry_column` now blindly selects every index level from 
`self._internal.index_spark_column_names`, but callers can pass a projected 
`df` that does not contain all of those columns (e.g., `_row_wise_operation` 
currently selects only `SPARK_DEFAULT_INDEX_NAME`). With a MultiIndex input 
this will raise an unresolved-column error when selecting the missing index 
levels. Consider either ensuring all callers preserve all index columns, or 
make `_query_geometry_column` resilient by only selecting index columns that 
are present in the provided `df` and keeping `index_fields/index_names` in sync.



##########
python/sedona/spark/geopandas/geoseries.py:
##########
@@ -2791,12 +3371,81 @@ def fillna(
         return result
 
     def explode(self, ignore_index=False, index_parts=False) -> "GeoSeries":
-        raise NotImplementedError(
-            _not_implemented_error(
-                "explode",
-                "Explodes multi-part geometries into separate single-part 
geometries.",
-            )
+        """
+        Explode multi-part geometries into multiple single geometries.
+
+        Single rows can become multiple rows. This is analogous to PostGIS
+        ``ST_Dump``. Geometry collections are expanded by one level, so a
+        multi-part geometry nested in a collection remains multi-part.
+
+        Parameters
+        ----------
+        ignore_index : bool, default False
+            If True, the resulting index is labelled 0, 1, ..., n - 1 and
+            ``index_parts`` is ignored.
+        index_parts : bool, default False
+            If True, append a zero-based index level identifying each geometry
+            produced from an input row.
+
+        Returns
+        -------
+        GeoSeries
+            Exploded geometries. The original index is repeated by default.
+
+        Examples
+        --------
+        >>> from sedona.spark.geopandas import GeoSeries
+        >>> from shapely.geometry import MultiPoint
+        >>> s = GeoSeries(
+        ...     [MultiPoint([(0, 0), (1, 1)]), MultiPoint([(2, 2), (3, 3)])]
         )
+        >>> s.explode(index_parts=True)
+        0  0    POINT (0 0)
+           1    POINT (1 1)
+        1  0    POINT (2 2)
+           1    POINT (3 3)
+        dtype: geometry
+        """
+        from pyspark.pandas.internal import InternalField
+

Review Comment:
   Redundant local import: `InternalField` is already imported at module scope, 
so re-importing it inside `explode()` adds noise and makes it easier to miss 
real dependency changes.



-- 
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]

Reply via email to