-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SEDONA-714] Add geopandas to spark arrow conversion. (#1825)
* SEDONA-714 Add geopandas to spark arrow conversion. * SEDONA-714 Add geopandas to spark arrow conversion. * SEDONA-714 Add geopandas to spark arrow conversion. * SEDONA-714 Add geopandas to spark arrow conversion. * SEDONA-714 Add geopandas to spark arrow conversion. * Update python/sedona/utils/geoarrow.py Co-authored-by: Dewey Dunnington <[email protected]> * SEDONA-714 Add geopandas to spark arrow conversion. * SEDONA-714 Add docs. * SEDONA-714 Add docs. --------- Co-authored-by: Dewey Dunnington <[email protected]>
- Loading branch information
1 parent
5007131
commit ebd6f67
Showing
5 changed files
with
263 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM squidfunk/mkdocs-material:9.6 | ||
|
||
RUN apk update | ||
RUN apk add gcc musl-dev linux-headers | ||
RUN pip install mkdocs-macros-plugin \ | ||
mkdocs-git-revision-date-localized-plugin \ | ||
mkdocs-jupyter \ | ||
mike |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
python/tests/utils/test_arrow_conversion_geopandas_to_sedona.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pytest | ||
|
||
from sedona.sql.types import GeometryType | ||
from sedona.utils.geoarrow import create_spatial_dataframe | ||
from tests.test_base import TestBase | ||
import geopandas as gpd | ||
import pyspark | ||
|
||
|
||
class TestGeopandasToSedonaWithArrow(TestBase): | ||
|
||
@pytest.mark.skipif( | ||
not pyspark.__version__.startswith("3.5"), | ||
reason="It's only working with Spark 3.5", | ||
) | ||
def test_conversion_dataframe(self): | ||
gdf = gpd.GeoDataFrame( | ||
{ | ||
"name": ["Sedona", "Apache"], | ||
"geometry": gpd.points_from_xy([0, 1], [0, 1]), | ||
} | ||
) | ||
|
||
df = create_spatial_dataframe(self.spark, gdf) | ||
|
||
assert df.count() == 2 | ||
assert df.columns == ["name", "geometry"] | ||
assert df.schema["geometry"].dataType == GeometryType() | ||
|
||
@pytest.mark.skipif( | ||
not pyspark.__version__.startswith("3.5"), | ||
reason="It's only working with Spark 3.5", | ||
) | ||
def test_different_geometry_positions(self): | ||
gdf = gpd.GeoDataFrame( | ||
{ | ||
"geometry": gpd.points_from_xy([0, 1], [0, 1]), | ||
"name": ["Sedona", "Apache"], | ||
} | ||
) | ||
|
||
gdf2 = gpd.GeoDataFrame( | ||
{ | ||
"name": ["Sedona", "Apache"], | ||
"name1": ["Sedona", "Apache"], | ||
"name2": ["Sedona", "Apache"], | ||
"geometry": gpd.points_from_xy([0, 1], [0, 1]), | ||
} | ||
) | ||
|
||
df1 = create_spatial_dataframe(self.spark, gdf) | ||
df2 = create_spatial_dataframe(self.spark, gdf2) | ||
|
||
assert df1.count() == 2 | ||
assert df1.columns == ["geometry", "name"] | ||
assert df1.schema["geometry"].dataType == GeometryType() | ||
|
||
assert df2.count() == 2 | ||
assert df2.columns == ["name", "name1", "name2", "geometry"] | ||
assert df2.schema["geometry"].dataType == GeometryType() | ||
|
||
@pytest.mark.skipif( | ||
not pyspark.__version__.startswith("3.5"), | ||
reason="It's only working with Spark 3.5", | ||
) | ||
def test_multiple_geometry_columns(self): | ||
gdf = gpd.GeoDataFrame( | ||
{ | ||
"name": ["Sedona", "Apache"], | ||
"geometry": gpd.points_from_xy([0, 1], [0, 1]), | ||
"geometry2": gpd.points_from_xy([0, 1], [0, 1]), | ||
} | ||
) | ||
|
||
df = create_spatial_dataframe(self.spark, gdf) | ||
|
||
assert df.count() == 2 | ||
assert df.columns == ["name", "geometry2", "geometry"] | ||
assert df.schema["geometry"].dataType == GeometryType() | ||
assert df.schema["geometry2"].dataType == GeometryType() | ||
|
||
@pytest.mark.skipif( | ||
not pyspark.__version__.startswith("3.5"), | ||
reason="It's only working with Spark 3.5", | ||
) | ||
def test_missing_geometry_column(self): | ||
gdf = gpd.GeoDataFrame( | ||
{ | ||
"name": ["Sedona", "Apache"], | ||
}, | ||
) | ||
|
||
with pytest.raises(ValueError): | ||
create_spatial_dataframe(self.spark, gdf) |