This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new db2e2bf820 [GH-2097] Geopandas: Clean up tests, reduce test time, add
LinearRing tests (#2145)
db2e2bf820 is described below
commit db2e2bf82056f58ee7894671c4d933f342136719
Author: Peter Nguyen <[email protected]>
AuthorDate: Wed Jul 23 13:56:18 2025 -0700
[GH-2097] Geopandas: Clean up tests, reduce test time, add LinearRing tests
(#2145)
* Clean up and simplify match series tests and add LinearRing tests
* Typo: remove specify
Co-authored-by: Copilot <[email protected]>
* Fix test_to_crs logic
---------
Co-authored-by: Copilot <[email protected]>
---
python/sedona/geopandas/geoseries.py | 3 +
.../tests/geopandas/test_match_geopandas_series.py | 439 ++++++++++-----------
2 files changed, 204 insertions(+), 238 deletions(-)
diff --git a/python/sedona/geopandas/geoseries.py
b/python/sedona/geopandas/geoseries.py
index 5e50d3787c..c4bbd8e51e 100644
--- a/python/sedona/geopandas/geoseries.py
+++ b/python/sedona/geopandas/geoseries.py
@@ -4285,6 +4285,9 @@ class GeoSeries(GeoFrame, pspd.Series):
*kwargs* that will be passed to json.dumps().
+ Note: Unlike geopandas, Sedona's implementation will replace
'LinearRing'
+ with 'LineString' in the GeoJSON output.
+
Returns
-------
JSON string
diff --git a/python/tests/geopandas/test_match_geopandas_series.py
b/python/tests/geopandas/test_match_geopandas_series.py
index 0b6ff9e00f..543ab729eb 100644
--- a/python/tests/geopandas/test_match_geopandas_series.py
+++ b/python/tests/geopandas/test_match_geopandas_series.py
@@ -62,6 +62,11 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.linestrings = [LineString([(x, x + 1), (x + 2, x + 3)]) for x in
range(3)]
+ self.linearrings = [
+ LinearRing([(x, x), (x + 1, x), (x + 1, x + 1), (x, x + 1), (x,
x)])
+ for x in range(3)
+ ]
+
self.multilinestrings = [
MultiLineString(
[[[x, x + 1], [x + 2, x + 3]], [[x + 4, x + 5], [x + 6, x +
7]]]
@@ -101,35 +106,35 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
)
]
- # (sql_table_name, geom)
self.geoms = [
- ("points", self.points),
- ("multipoints", self.multipoints),
- ("linestrings", self.linestrings),
- ("multilinestrings", self.multilinestrings),
- ("polygons", self.polygons),
- ("multipolygons", self.multipolygons),
- ("geomcollection", self.geomcollection),
+ self.points,
+ self.multipoints,
+ self.linestrings,
+ self.linearrings,
+ self.multilinestrings,
+ self.polygons,
+ self.multipolygons,
+ self.geomcollection,
]
- # create the tables in sedona spark
- for i, (table_name, geoms) in enumerate(self.geoms):
- wkt_string = [g.wkt for g in geoms]
- pd_df = pd.DataFrame({"id": i, "geometry": wkt_string})
- spark_df = self.spark.createDataFrame(pd_df)
- spark_df.createOrReplaceTempView(table_name)
+ self.pairs = [
+ (self.points, self.multipolygons),
+ (self.geomcollection, self.polygons),
+ (self.linestrings, self.multipoints),
+ (self.linearrings, self.multilinestrings),
+ ]
def teardown_method(self):
shutil.rmtree(self.tempdir)
def test_constructor(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
gpd_series = gpd.GeoSeries(geom)
assert isinstance(gpd_series, gpd.GeoSeries)
assert isinstance(gpd_series.geometry, gpd.GeoSeries)
def test_to_geopandas(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom)
gpd_result = gpd.GeoSeries(geom)
# The below method calls to_geopandas() on sgpd_result, so we
don't do it here
@@ -178,7 +183,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
assert type(area) is ps.Series
assert area.count() == 2
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).area
gpd_result = gpd.GeoSeries(geom).area
self.check_pd_series_equal(sgpd_result, gpd_result)
@@ -189,7 +194,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
assert type(buffer) is GeoSeries
assert buffer.count() == 2
- for _, geom in self.geoms:
+ for geom in self.geoms:
dist = 0.2
sgpd_result = GeoSeries(geom).buffer(dist)
gpd_result = gpd.GeoSeries(geom).buffer(dist)
@@ -210,7 +215,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
assert os.path.exists(temp_file_path)
def test_geometry(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
gpd_result = gpd.GeoSeries(geom).geometry
sgpd_result = GeoSeries(geom).geometry
assert isinstance(sgpd_result, GeoSeries)
@@ -244,14 +249,14 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
pass
def test_from_wkb(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
wkb = [g.wkb for g in geom]
sgpd_result = GeoSeries.from_wkb(wkb)
gpd_result = gpd.GeoSeries.from_wkb(wkb)
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
def test_from_wkt(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
wkt = [g.wkt for g in geom]
sgpd_result = GeoSeries.from_wkt(wkt)
gpd_result = gpd.GeoSeries.from_wkt(wkt)
@@ -285,7 +290,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
if parse_version(gpd.__version__) < parse_version("1.0.0"):
return
- for _, geom in self.geoms:
+ for geom in self.geoms:
gpd_series = gpd.GeoSeries(geom)
gpd_result = gpd.GeoSeries.from_arrow(gpd_series.to_arrow())
@@ -297,7 +302,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
@pytest.mark.parametrize("fun", ["isna", "isnull"])
def test_isna(self, fun):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = getattr(GeoSeries(geom), fun)()
assert isinstance(sgpd_result, ps.Series)
gpd_result = getattr(gpd.GeoSeries(geom), fun)()
@@ -305,7 +310,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
@pytest.mark.parametrize("fun", ["notna", "notnull"])
def test_notna(self, fun):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = getattr(GeoSeries(geom), fun)()
assert isinstance(sgpd_result, ps.Series)
gpd_result = getattr(gpd.GeoSeries(geom), fun)()
@@ -318,7 +323,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.check_pd_series_equal(sgpd_result, gpd_result)
def test_fillna(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).fillna()
gpd_result = gpd.GeoSeries(geom).fillna()
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
@@ -346,17 +351,13 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
pass
def test_to_crs(self):
- for _, geom in self.geoms:
- sgpd_result = GeoSeries(geom, crs=4326)
- gpd_result = gpd.GeoSeries(geom, crs=4326)
- self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
-
- sgpd_result = sgpd_result.to_crs(epsg=3857)
- gpd_result = gpd_result.to_crs(epsg=3857)
+ for geom in self.geoms:
+ sgpd_result = GeoSeries(geom, crs=4326).to_crs(epsg=3857)
+ gpd_result = gpd.GeoSeries(geom, crs=4326).to_crs(epsg=3857)
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
def test_bounds(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).bounds
gpd_result = gpd.GeoSeries(geom).bounds
pd.testing.assert_frame_equal(
@@ -366,26 +367,29 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
def test_total_bounds(self):
import numpy as np
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).total_bounds
gpd_result = gpd.GeoSeries(geom).total_bounds
np.testing.assert_array_equal(sgpd_result, gpd_result)
def test_estimate_utm_crs(self):
for crs in ["epsg:4326", "epsg:3857"]:
- for _, geom in self.geoms:
+ for geom in self.geoms:
gpd_result = gpd.GeoSeries(geom, crs=crs).estimate_utm_crs()
sgpd_result = GeoSeries(geom, crs=crs).estimate_utm_crs()
assert sgpd_result == gpd_result
def test_to_json(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
+ # Sedona converts it to LineString, so the outputs will be
different
+ if isinstance(geom[0], LinearRing):
+ continue
sgpd_result = GeoSeries(geom).to_json()
gpd_result = gpd.GeoSeries(geom).to_json()
assert sgpd_result == gpd_result
def test_to_wkb(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).to_wkb()
gpd_result = gpd.GeoSeries(geom).to_wkb()
self.check_pd_series_equal(sgpd_result, gpd_result)
@@ -395,7 +399,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.check_pd_series_equal(sgpd_result, gpd_result)
def test_to_wkt(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
ps_series = GeoSeries(geom).to_wkt()
pd_series = gpd.GeoSeries(geom).to_wkt()
# There are slight variations of valid wkt (e.g valid parentheses
being optional),
@@ -411,7 +415,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
import pyarrow as pa
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = pa.array(GeoSeries(geom).to_arrow())
gpd_result = pa.array(gpd.GeoSeries(geom).to_arrow())
assert sgpd_result == gpd_result
@@ -420,7 +424,10 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
pass
def test_geom_type(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
+ # Sedona converts it to LineString, so the outputs will be
different
+ if isinstance(geom[0], LinearRing):
+ continue
sgpd_result = GeoSeries(geom).geom_type
gpd_result = gpd.GeoSeries(geom).geom_type
self.check_pd_series_equal(sgpd_result, gpd_result)
@@ -429,14 +436,14 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
pass
def test_length(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).length
assert isinstance(sgpd_result, ps.Series)
gpd_result = gpd.GeoSeries(geom).length
self.check_pd_series_equal(sgpd_result, gpd_result)
def test_is_valid(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).is_valid
assert isinstance(sgpd_result, ps.Series)
gpd_result = gpd.GeoSeries(geom).is_valid
@@ -470,7 +477,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
raise ValueError(f"Unexpected result: {a} not equivalent to
{e}")
def test_is_empty(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).is_empty
assert isinstance(sgpd_result, ps.Series)
gpd_result = gpd.GeoSeries(geom).is_empty
@@ -489,59 +496,53 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
if parse_version(gpd.__version__) < parse_version("1.0.0"):
pytest.skip("geopandas < 1.0.0 does not support dwithin")
- for i, (_, geom) in enumerate(self.geoms):
- for _, geom2 in self.geoms[i:]:
- sgpd_result = GeoSeries(geom).dwithin(GeoSeries(geom2),
distance=1)
+ for geom, geom2 in self.pairs:
+ sgpd_result = GeoSeries(geom).dwithin(GeoSeries(geom2), distance=1)
+ gpd_result = gpd.GeoSeries(geom).dwithin(gpd.GeoSeries(geom2),
distance=1)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).dwithin(
+ GeoSeries(geom2), distance=1, align=False
+ )
gpd_result = gpd.GeoSeries(geom).dwithin(
- gpd.GeoSeries(geom2), distance=1
+ gpd.GeoSeries(geom2), distance=1, align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).dwithin(
- GeoSeries(geom2), distance=1, align=False
- )
- gpd_result = gpd.GeoSeries(geom).dwithin(
- gpd.GeoSeries(geom2), distance=1, align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_difference(self):
- for i, (_, geom) in enumerate(self.geoms):
- for _, geom2 in self.geoms[i:]:
- # Sedona doesn't support difference for GeometryCollections
- if isinstance(geom[0], GeometryCollection) or isinstance(
- geom2[0], GeometryCollection
- ):
- continue
- # Operation doesn't work on invalid geometries
- if (
- not gpd.GeoSeries(geom).is_valid.all()
- or not gpd.GeoSeries(geom2).is_valid.all()
- ):
- continue
-
- sgpd_result = GeoSeries(geom).difference(GeoSeries(geom2))
- gpd_result =
gpd.GeoSeries(geom).difference(gpd.GeoSeries(geom2))
- self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+ for geom, geom2 in self.pairs:
+ # Sedona doesn't support difference for GeometryCollections
+ if isinstance(geom[0], GeometryCollection) or isinstance(
+ geom2[0], GeometryCollection
+ ):
+ continue
+ # Operation doesn't work on invalid geometries
+ if (
+ not gpd.GeoSeries(geom).is_valid.all()
+ or not gpd.GeoSeries(geom2).is_valid.all()
+ ):
+ continue
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).difference(
- GeoSeries(geom2), align=False
- )
- gpd_result = gpd.GeoSeries(geom).difference(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+ sgpd_result = GeoSeries(geom).difference(GeoSeries(geom2))
+ gpd_result = gpd.GeoSeries(geom).difference(gpd.GeoSeries(geom2))
+ self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).difference(GeoSeries(geom2),
align=False)
+ gpd_result = gpd.GeoSeries(geom).difference(
+ gpd.GeoSeries(geom2), align=False
+ )
+ self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
def test_is_simple(self):
+ # 'is_simple' is meaningful only for `LineStrings` and `LinearRings`
data = [
LineString([(0, 0), (0, 0)]),
LineString([(0, 0), (1, 1), (1, -1), (0, 1)]),
LineString([(0, 0), (1, 1), (0, 0)]),
- # Errors for LinearRing: issue #2120
- # LinearRing([(0, 0), (1, 1), (1, 0), (0, 1), (0, 0)]),
- # LinearRing([(0, 0), (-1, 1), (-1, -1), (1, -1)]),
+ LinearRing([(0, 0), (1, 1), (1, 0), (0, 1), (0, 0)]),
+ LinearRing([(0, 0), (-1, 1), (-1, -1), (1, -1)]),
]
sgpd_result = GeoSeries(data).is_simple
gpd_result = gpd.GeoSeries(data).is_simple
@@ -557,7 +558,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
pass
def test_has_z(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).has_z
gpd_result = gpd.GeoSeries(geom).has_z
self.check_pd_series_equal(sgpd_result, gpd_result)
@@ -569,7 +570,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
if parse_version(gpd.__version__) < parse_version("1.0.0"):
pytest.skip("geopandas get_geometry requires version 1.0.0 or
higher")
- for _, geom in self.geoms:
+ for geom in self.geoms:
# test negative index, in-bounds index, and out of bounds index
for index in [-1, 0, len(geom) + 1]:
sgpd_result = GeoSeries(geom).get_geometry(index)
@@ -584,7 +585,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
def test_boundary(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
# Shapely < 2.0 doesn't support GeometryCollection for boundary
operation
if shapely.__version__ < "2.0.0" and isinstance(
geom[0], GeometryCollection
@@ -595,7 +596,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
def test_centroid(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).centroid
gpd_result = gpd.GeoSeries(geom).centroid
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
@@ -613,7 +614,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
pass
def test_envelope(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).envelope
gpd_result = gpd.GeoSeries(geom).envelope
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
@@ -661,12 +662,12 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
if shapely.__version__ < "2.1.0":
pytest.skip("geopandas make_valid requires shapely >= 2.1.0")
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).make_valid(method="structure")
gpd_result = gpd.GeoSeries(geom).make_valid(method="structure")
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_result = GeoSeries(geom).make_valid(
method="structure", keep_collapsed=False
)
@@ -708,7 +709,7 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
# Union all the valid geometries
# Neither our nor geopandas' implementation supports invalid geometries
- lst = [g for _, geom in self.geoms for g in geom if g.is_valid]
+ lst = [g for geom in self.geoms for g in geom if g.is_valid]
sgpd_result = GeoSeries(lst).union_all()
gpd_result = gpd.GeoSeries(lst).union_all()
self.check_geom_equals(sgpd_result, gpd_result)
@@ -719,46 +720,40 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.check_geom_equals(sgpd_result, gpd_result)
def test_crosses(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- if self.contains_any_geom_collection(geom, geom2):
- continue
+ for geom, geom2 in self.pairs:
+ if self.contains_any_geom_collection(geom, geom2):
+ continue
- # We explicitly specify align=True to quite warnings in
geopandas, despite it being the default
+ # We explicitly specify align=True to quite warnings in geopandas,
despite it being the default
+ gpd_result = gpd.GeoSeries(geom).crosses(gpd.GeoSeries(geom2),
align=True)
+ sgpd_result = GeoSeries(geom).crosses(GeoSeries(geom2), align=True)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).crosses(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).crosses(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
- sgpd_result = GeoSeries(geom).crosses(GeoSeries(geom2),
align=True)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).crosses(GeoSeries(geom2),
align=False)
- gpd_result = gpd.GeoSeries(geom).crosses(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_disjoint(self):
pass
def test_intersects(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- sgpd_result = GeoSeries(geom).intersects(GeoSeries(geom2),
align=True)
+ for geom, geom2 in self.pairs:
+ sgpd_result = GeoSeries(geom).intersects(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).intersects(
+ gpd.GeoSeries(geom2), align=True
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).intersects(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).intersects(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).intersects(
- GeoSeries(geom2), align=False
- )
- gpd_result = gpd.GeoSeries(geom).intersects(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_intersection(self):
geometries = [
Polygon([(0, 0), (1, 0), (1, 1)]),
@@ -782,180 +777,148 @@ class TestMatchGeopandasSeries(TestGeopandasBase):
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
assert sgpd_result.index.to_pandas().equals(gpd_result.index)
- for g1 in geometries:
- for g2 in geometries:
- sgpd_result = GeoSeries(g1).intersection(GeoSeries(g2))
- gpd_result = gpd.GeoSeries(g1).intersection(gpd.GeoSeries(g2))
- self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
-
# Ensure both align True and False work correctly
- for _, g1 in self.geoms:
- for _, g2 in self.geoms:
- gpd_series1, gpd_series2 = gpd.GeoSeries(g1), gpd.GeoSeries(g2)
- # The original geopandas intersection method fails on invalid
geometries
- if not gpd_series1.is_valid.all() or not
gpd_series2.is_valid.all():
- continue
- sgpd_result = GeoSeries(g1).intersection(GeoSeries(g2))
- gpd_result = gpd_series1.intersection(gpd_series2)
- self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+ for geom, geom2 in self.pairs:
+ gpd_series1, gpd_series2 = gpd.GeoSeries(geom),
gpd.GeoSeries(geom2)
+ # The original geopandas intersection method fails on invalid
geometries
+ if not gpd_series1.is_valid.all() or not
gpd_series2.is_valid.all():
+ continue
+ sgpd_result = GeoSeries(geom).intersection(GeoSeries(geom2))
+ gpd_result = gpd_series1.intersection(gpd_series2)
+ self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
- if len(g1) == len(g2):
- sgpd_result = GeoSeries(g1).intersection(GeoSeries(g2),
align=False)
- gpd_result = gpd_series1.intersection(gpd_series2,
align=False)
- self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).intersection(
+ GeoSeries(geom2), align=False
+ )
+ gpd_result = gpd_series1.intersection(gpd_series2, align=False)
+ self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
def test_intersection_all(self):
pass
def test_overlaps(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- # Sedona's results differ from geopandas for these cases
- if geom == geom2 or self.contains_any_geom_collection(geom,
geom2):
- continue
+ for geom, geom2 in self.pairs:
+ # Sedona's results differ from geopandas for these cases
+ if geom == geom2 or self.contains_any_geom_collection(geom, geom2):
+ continue
+
+ sgpd_result = GeoSeries(geom).overlaps(GeoSeries(geom2,
align=True))
+ gpd_result = gpd.GeoSeries(geom).overlaps(gpd.GeoSeries(geom2),
align=True)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
- sgpd_result = GeoSeries(geom).overlaps(GeoSeries(geom2,
align=True))
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).overlaps(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).overlaps(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).overlaps(
- GeoSeries(geom2), align=False
- )
- gpd_result = gpd.GeoSeries(geom).overlaps(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_touches(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- if self.contains_any_geom_collection(geom, geom2):
- continue
- sgpd_result = GeoSeries(geom).touches(GeoSeries(geom2),
align=True)
+ for geom, geom2 in self.pairs:
+ if self.contains_any_geom_collection(geom, geom2):
+ continue
+ sgpd_result = GeoSeries(geom).touches(GeoSeries(geom2), align=True)
+ gpd_result = gpd.GeoSeries(geom).touches(gpd.GeoSeries(geom2),
align=True)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).touches(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).touches(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).touches(GeoSeries(geom2),
align=False)
- gpd_result = gpd.GeoSeries(geom).touches(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_within(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- if geom == geom2 or self.contains_any_geom_collection(geom,
geom2):
- continue
+ for geom, geom2 in self.pairs:
+ if geom == geom2 or self.contains_any_geom_collection(geom, geom2):
+ continue
+
+ sgpd_result = GeoSeries(geom).within(GeoSeries(geom2), align=True)
+ gpd_result = gpd.GeoSeries(geom).within(gpd.GeoSeries(geom2),
align=True)
+
+ self.check_pd_series_equal(sgpd_result, gpd_result)
- sgpd_result = GeoSeries(geom).within(GeoSeries(geom2),
align=True)
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).within(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).within(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
-
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).within(GeoSeries(geom2),
align=False)
- gpd_result = gpd.GeoSeries(geom).within(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_covers(self):
if parse_version(gpd.__version__) < parse_version("0.8.0"):
pytest.skip("geopandas < 0.8.0 does not support covered_by")
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- if geom == geom2 or self.contains_any_geom_collection(geom,
geom2):
- continue
+ for geom, geom2 in self.pairs:
+ if geom == geom2 or self.contains_any_geom_collection(geom, geom2):
+ continue
+
+ sgpd_result = GeoSeries(geom).covers(GeoSeries(geom2), align=True)
+ gpd_result = gpd.GeoSeries(geom).covers(gpd.GeoSeries(geom2),
align=True)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
- sgpd_result = GeoSeries(geom).covers(GeoSeries(geom2),
align=True)
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).covers(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).covers(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).covers(GeoSeries(geom2),
align=False)
- gpd_result = gpd.GeoSeries(geom).covers(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_covered_by(self):
if parse_version(shapely.__version__) < parse_version("2.0.0"):
pytest.skip("shapely < 2.0.0 does not support covered_by")
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- if geom == geom2 or self.contains_any_geom_collection(geom,
geom2):
- continue
+ for geom, geom2 in self.pairs:
+ if geom == geom2 or self.contains_any_geom_collection(geom, geom2):
+ continue
- sgpd_result = GeoSeries(geom).covered_by(GeoSeries(geom2),
align=True)
+ sgpd_result = GeoSeries(geom).covered_by(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).covered_by(
+ gpd.GeoSeries(geom2), align=True
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).covered_by(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).covered_by(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).covered_by(
- GeoSeries(geom2), align=False
- )
- gpd_result = gpd.GeoSeries(geom).covered_by(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_distance(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- sgpd_result = GeoSeries(geom).distance(GeoSeries(geom2),
align=True)
+ for geom, geom2 in self.pairs:
+ sgpd_result = GeoSeries(geom).distance(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).distance(gpd.GeoSeries(geom2),
align=True)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).distance(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).distance(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).distance(
- GeoSeries(geom2), align=False
- )
- gpd_result = gpd.GeoSeries(geom).distance(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_contains(self):
- for _, geom in self.geoms:
- for _, geom2 in self.geoms:
- if geom == geom2 or self.contains_any_geom_collection(geom,
geom2):
- continue
- sgpd_result = GeoSeries(geom).contains(GeoSeries(geom2),
align=True)
+ for geom, geom2 in self.pairs:
+ if geom == geom2 or self.contains_any_geom_collection(geom, geom2):
+ continue
+ sgpd_result = GeoSeries(geom).contains(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).contains(gpd.GeoSeries(geom2),
align=True)
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).contains(GeoSeries(geom2),
align=False)
gpd_result = gpd.GeoSeries(geom).contains(
- gpd.GeoSeries(geom2), align=True
+ gpd.GeoSeries(geom2), align=False
)
self.check_pd_series_equal(sgpd_result, gpd_result)
- if len(geom) == len(geom2):
- sgpd_result = GeoSeries(geom).contains(
- GeoSeries(geom2), align=False
- )
- gpd_result = gpd.GeoSeries(geom).contains(
- gpd.GeoSeries(geom2), align=False
- )
- self.check_pd_series_equal(sgpd_result, gpd_result)
-
def test_contains_properly(self):
pass
def test_set_crs(self):
- for _, geom in self.geoms:
+ for geom in self.geoms:
sgpd_series = GeoSeries(geom)
gpd_series = gpd.GeoSeries(geom)
assert sgpd_series.crs == gpd_series.crs