Skip to content

Commit

Permalink
[SEDONA-548] Fix Python Dataframe API Constructor registrations (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
furqaankhan committed Apr 26, 2024
1 parent a7ad5f0 commit 9ff93f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 16 additions & 8 deletions python/sedona/sql/st_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def ST_GeomFromKML(kml_string: ColumnOrName) -> Column:


@validate_argument_types
def ST_GeomFromText(wkt: ColumnOrName) -> Column:
def ST_GeomFromText(wkt: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None) -> Column:
"""Generate a geometry column from a Well-Known Text (WKT) string column.
This is an alias of ST_GeomFromWKT.
Expand All @@ -93,7 +93,9 @@ def ST_GeomFromText(wkt: ColumnOrName) -> Column:
:return: Geometry column representing the WKT string.
:rtype: Column
"""
return _call_constructor_function("ST_GeomFromText", wkt)
args = (wkt) if srid is None else (wkt, srid)

return _call_constructor_function("ST_GeomFromText", args)


@validate_argument_types
Expand All @@ -109,7 +111,7 @@ def ST_GeomFromWKB(wkb: ColumnOrName) -> Column:


@validate_argument_types
def ST_GeomFromWKT(wkt: ColumnOrName) -> Column:
def ST_GeomFromWKT(wkt: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None) -> Column:
"""Generate a geometry column from a Well-Known Text (WKT) string column.
This is an alias of ST_GeomFromText.
Expand All @@ -118,7 +120,9 @@ def ST_GeomFromWKT(wkt: ColumnOrName) -> Column:
:return: Geometry column representing the WKT string.
:rtype: Column
"""
return _call_constructor_function("ST_GeomFromWKT", wkt)
args = (wkt) if srid is None else (wkt, srid)

return _call_constructor_function("ST_GeomFromWKT", args)

@validate_argument_types
def ST_GeomFromEWKT(ewkt: ColumnOrName) -> Column:
Expand Down Expand Up @@ -261,23 +265,27 @@ def ST_PolygonFromText(coords: ColumnOrName, delimiter: ColumnOrName) -> Column:
return _call_constructor_function("ST_PolygonFromText", (coords, delimiter))

@validate_argument_types
def ST_MPolyFromText(wkt: ColumnOrName) -> Column:
def ST_MPolyFromText(wkt: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None) -> Column:
"""Generate multiPolygon geometry from a multiPolygon WKT representation.
:param wkt: multiPolygon WKT string column to generate from.
:type wkt: ColumnOrName
:return: multiPolygon geometry generated from the wkt column.
:rtype: Column
"""
return _call_constructor_function("ST_MPolyFromText", wkt)
args = (wkt) if srid is None else (wkt, srid)

return _call_constructor_function("ST_MPolyFromText", args)

@validate_argument_types
def ST_MLineFromText(wkt: ColumnOrName) -> Column:
def ST_MLineFromText(wkt: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None) -> Column:
"""Generate multiLineString geometry from a multiLineString WKT representation.
:param wkt: multiLineString WKT string column to generate from.
:type wkt: ColumnOrName
:return: multiLineString geometry generated from the wkt column.
:rtype: Column
"""
return _call_constructor_function("ST_MLineFromText", wkt)
args = (wkt) if srid is None else (wkt, srid)

return _call_constructor_function("ST_MLineFromText", args)
12 changes: 12 additions & 0 deletions python/tests/sql/test_dataframe_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@
(stc.ST_GeomFromGML, ("gml",), "constructor", "", "LINESTRING (-71.16 42.25, -71.17 42.25, -71.18 42.25)"),
(stc.ST_GeomFromKML, ("kml",), "constructor", "", "LINESTRING (-71.16 42.26, -71.17 42.26)"),
(stc.ST_GeomFromText, ("wkt",), "linestring_wkt", "", "LINESTRING (1 2, 3 4)"),
(stc.ST_GeomFromText, ("wkt",4326), "linestring_wkt", "", "LINESTRING (1 2, 3 4)"),
(stc.ST_GeomFromWKB, ("wkb",), "constructor", "ST_ReducePrecision(geom, 2)", "LINESTRING (-2.1 -0.35, -1.5 -0.67)"),
(stc.ST_GeomFromWKT, ("wkt",), "linestring_wkt", "", "LINESTRING (1 2, 3 4)"),
(stc.ST_GeomFromWKT, ("wkt",4326), "linestring_wkt", "", "LINESTRING (1 2, 3 4)"),
(stc.ST_GeomFromEWKT, ("ewkt",), "linestring_ewkt", "", "LINESTRING (1 2, 3 4)"),
(stc.ST_LineFromText, ("wkt",), "linestring_wkt", "", "LINESTRING (1 2, 3 4)"),
(stc.ST_LineStringFromText, ("multiple_point", lambda: f.lit(',')), "constructor", "", "LINESTRING (0 0, 1 0, 1 1, 0 0)"),
(stc.ST_Point, ("x", "y"), "constructor", "", "POINT (0 1)"),
(stc.ST_PointZ, ("x", "y", "z", 4326), "constructor", "", "POINT Z (0 1 2)"),
(stc.ST_PointZ, ("x", "y", "z"), "constructor", "", "POINT Z (0 1 2)"),
(stc.ST_MPolyFromText, ("mpoly",), "constructor", "" , "MULTIPOLYGON (((0 0, 20 0, 20 20, 0 20, 0 0), (5 5, 5 7, 7 7, 7 5, 5 5)))"),
(stc.ST_MPolyFromText, ("mpoly", 4326), "constructor", "" , "MULTIPOLYGON (((0 0, 20 0, 20 20, 0 20, 0 0), (5 5, 5 7, 7 7, 7 5, 5 5)))"),
(stc.ST_MLineFromText, ("mline", ), "constructor", "" , "MULTILINESTRING ((1 2, 3 4), (4 5, 6 7))"),
(stc.ST_MLineFromText, ("mline", 4326), "constructor", "" , "MULTILINESTRING ((1 2, 3 4), (4 5, 6 7))"),
(stc.ST_PointFromText, ("single_point", lambda: f.lit(',')), "constructor", "", "POINT (0 1)"),
(stc.ST_MakePoint, ("x", "y", "z"), "constructor", "", "POINT Z (0 1 2)"),
(stc.ST_PolygonFromEnvelope, ("minx", "miny", "maxx", "maxy"), "min_max_x_y", "", "POLYGON ((0 1, 0 3, 2 3, 2 1, 0 1))"),
Expand Down Expand Up @@ -382,6 +390,8 @@ class TestDataFrameAPI(TestBase):
@pytest.fixture
def base_df(self, request):
wkb = '0102000000020000000000000084d600c00000000080b5d6bf00000060e1eff7bf00000080075de5bf'
mpoly = 'MULTIPOLYGON(((0 0 ,20 0 ,20 20 ,0 20 ,0 0 ),(5 5 ,5 7 ,7 7 ,7 5 ,5 5)))'
mline = 'MULTILINESTRING((1 2, 3 4), (4 5, 6 7))'
geojson = "{ \"type\": \"Feature\", \"properties\": { \"prop\": \"01\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0.0, 1.0 ] }},"
gml_string = "<gml:LineString srsName=\"EPSG:4269\"><gml:coordinates>-71.16,42.25 -71.17,42.25 -71.18,42.25</gml:coordinates></gml:LineString>"
kml_string = "<LineString><coordinates>-71.16,42.26 -71.17,42.26</coordinates></LineString>"
Expand All @@ -394,6 +404,8 @@ def base_df(self, request):
"'0.0,1.0' AS single_point",
"'0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0' AS multiple_point",
f"X'{wkb}' AS wkb",
f"'{mpoly}' AS mpoly",
f"'{mline}' AS mline",
f"'{geojson}' AS geojson",
"'s00twy01mt' AS geohash",
f"'{gml_string}' AS gml",
Expand Down

0 comments on commit 9ff93f4

Please sign in to comment.