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


##########
python/sedona/spark/sql/st_constructors.py:
##########
@@ -550,6 +550,42 @@ def ST_MakePoint(
     return _call_constructor_function("ST_MakePoint", (args))
 
 
+@validate_argument_types
+def ST_MakeBox2D(
+    lower_left: ColumnOrName,
+    upper_right: ColumnOrName,
+) -> Column:
+    """Construct a Box2D from two corner points (lower-left, upper-right).
+
+    Coordinates are taken verbatim — no swapping or ordering validation. NULL 
or
+    empty point inputs return NULL. Non-point inputs raise an error.
+
+    :param lower_left: Lower-left corner Point.
+    :type lower_left: ColumnOrName
+    :param upper_right: Upper-right corner Point.
+    :type upper_right: ColumnOrName
+    :return: Box2D column.
+    :rtype: Column
+    """
+    return _call_constructor_function("ST_MakeBox2D", (lower_left, 
upper_right))

Review Comment:
   ST_MakeBox2D dispatches via `st_constructors.ST_MakeBox2D` on the JVM. The 
Scala `org.apache.spark.sql.sedona_sql.expressions.st_constructors` object in 
this repo does not define an `ST_MakeBox2D` Column wrapper yet, so this Python 
wrapper will fail at runtime. Add the Scala wrapper method (or switch the 
Python call path to invoke the SQL function directly) before merging.



##########
python/sedona/spark/sql/st_functions.py:
##########
@@ -649,6 +649,20 @@ def ST_EndPoint(line_string: ColumnOrName) -> Column:
     return _call_st_function("ST_EndPoint", line_string)
 
 
+@validate_argument_types
+def ST_Box2D(geometry: ColumnOrName) -> Column:
+    """Get the planar bounding box (Box2D) of a geometry.
+
+    Returns NULL for null or empty input.
+
+    :param geometry: Geometry column to compute the bounding box of.
+    :type geometry: ColumnOrName
+    :return: Box2D bounding box of the geometry.
+    :rtype: Column
+    """
+    return _call_st_function("ST_Box2D", geometry)

Review Comment:
   ST_Box2D uses _call_st_function("ST_Box2D", ...) which dispatches to the JVM 
object `st_functions.ST_Box2D`. In this repo the Scala 
`org.apache.spark.sql.sedona_sql.expressions.st_functions` object does not 
currently define an `ST_Box2D` Column wrapper, so this Python binding will fail 
at runtime with a missing-method/attribute error. Add the corresponding Scala 
wrapper (or change the Python dispatch to call the SQL function by name without 
relying on Scala wrappers) so the binding is actually callable.



##########
python/sedona/spark/sql/st_constructors.py:
##########
@@ -550,6 +550,42 @@ def ST_MakePoint(
     return _call_constructor_function("ST_MakePoint", (args))
 
 
+@validate_argument_types
+def ST_MakeBox2D(
+    lower_left: ColumnOrName,
+    upper_right: ColumnOrName,
+) -> Column:
+    """Construct a Box2D from two corner points (lower-left, upper-right).
+
+    Coordinates are taken verbatim — no swapping or ordering validation. NULL 
or
+    empty point inputs return NULL. Non-point inputs raise an error.
+
+    :param lower_left: Lower-left corner Point.
+    :type lower_left: ColumnOrName
+    :param upper_right: Upper-right corner Point.
+    :type upper_right: ColumnOrName
+    :return: Box2D column.
+    :rtype: Column
+    """
+    return _call_constructor_function("ST_MakeBox2D", (lower_left, 
upper_right))
+
+
+@validate_argument_types
+def ST_GeomFromBox2D(box: ColumnOrName) -> Column:
+    """Convert a Box2D to a Geometry.
+
+    Dispatches on dimensionality (matching PostGIS box2d::geometry and
+    Sedona's ST_Envelope): POINT for 0-D boxes, LINESTRING for 1-D boxes,
+    POLYGON otherwise. NULL on null input.
+
+    :param box: Box2D column to convert.
+    :type box: ColumnOrName
+    :return: Geometry column.
+    :rtype: Column
+    """
+    return _call_constructor_function("ST_GeomFromBox2D", box)

Review Comment:
   ST_GeomFromBox2D dispatches via `st_constructors.ST_GeomFromBox2D` on the 
JVM, but the Scala 
`org.apache.spark.sql.sedona_sql.expressions.st_constructors` object does not 
currently expose an `ST_GeomFromBox2D` Column wrapper. This makes the Python 
binding unusable at runtime until the Scala wrapper is added (or the Python 
dispatch is changed to call the SQL function directly).



##########
python/sedona/spark/sql/st_aggregates.py:
##########
@@ -41,6 +41,21 @@ def ST_Envelope_Aggr(geometry: ColumnOrName) -> Column:
     return _call_aggregate_function("ST_Envelope_Aggr", geometry)
 
 
+@validate_argument_types
+def ST_Extent(geometry: ColumnOrName) -> Column:
+    """Aggregate Function: Get the bounding box (Box2D) of a geometry column.
+
+    Returns NULL when the input contains no rows or all rows are null/empty
+    geometries. Mirrors PostGIS ST_Extent.
+
+    :param geometry: Geometry column to aggregate.
+    :type geometry: ColumnOrName
+    :return: Box2D representing the union of bounding boxes of the geometry 
column.
+    :rtype: Column
+    """
+    return _call_aggregate_function("ST_Extent", geometry)

Review Comment:
   ST_Extent dispatches via `st_aggregates.ST_Extent` on the JVM, but the Scala 
`org.apache.spark.sql.sedona_sql.expressions.st_aggregates` object in this repo 
does not define an `ST_Extent` Column wrapper. As a result, this Python wrapper 
will fail at runtime. Add the missing Scala wrapper (or adjust the Python 
dispatch mechanism) so the binding can actually be called from PySpark.



##########
python/tests/sql/test_function.py:
##########
@@ -185,6 +185,28 @@ def test_st_shiftlongitude(self):
         actual = function_df.take(1)[0][0].wkt
         assert actual == "LINESTRING (179 10, -179 10)"
 
+    def test_st_box_2d(self):
+        df = self.spark.sql("""
+            SELECT
+              ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 2))')) 
AS bbox,
+              ST_Box2D(ST_GeomFromText('POINT EMPTY')) AS bbox_empty,

Review Comment:
   These new tests validate the SQL surface via `spark.sql(...)`, but they do 
not exercise the new PySpark Column wrappers added in this PR (e.g., 
`st_functions.ST_Box2D`, `st_constructors.ST_MakeBox2D`, 
`st_aggregates.ST_Extent`). Add DataFrame API coverage in 
`python/tests/sql/test_dataframe_api.py` (consistent with other wrapper tests) 
so wrapper dispatch/argument handling is actually tested.



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