jiayuasu commented on code in PR #2732:
URL: https://github.com/apache/sedona/pull/2732#discussion_r2929578758
##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -1285,6 +1285,104 @@ def test_relate(self):
)
self.check_pd_series_equal(sgpd_result, gpd_result)
+ def test_frechet_distance(self):
+ line_pairs = [
+ (self.linestrings, self.linestrings),
+ (self.linearrings, self.linearrings),
+ (self.linestrings, self.linearrings),
+ ]
+ for geom, geom2 in line_pairs:
+ # Skip pairs containing empty geometries
+ if any(g.is_empty for g in geom) or any(g.is_empty for g in geom2):
+ continue
+
Review Comment:
Correction: my previous reply was wrong. Empty geometries DO work in Sedona
GeoSeries — the failures I observed were caused by a stale JAR (pre-PR #2730
fix). All skips have been removed in 2d1b4ac. The match tests now include empty
geometries and pass.
##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -1285,6 +1285,104 @@ def test_relate(self):
)
self.check_pd_series_equal(sgpd_result, gpd_result)
+ def test_frechet_distance(self):
+ line_pairs = [
+ (self.linestrings, self.linestrings),
+ (self.linearrings, self.linearrings),
+ (self.linestrings, self.linearrings),
+ ]
+ for geom, geom2 in line_pairs:
+ # Skip pairs containing empty geometries
+ if any(g.is_empty for g in geom) or any(g.is_empty for g in geom2):
+ continue
+
+ sgpd_result = GeoSeries(geom).frechet_distance(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).frechet_distance(
+ gpd.GeoSeries(geom2), align=True
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).frechet_distance(
+ GeoSeries(geom2), align=False
+ )
+ gpd_result = gpd.GeoSeries(geom).frechet_distance(
+ gpd.GeoSeries(geom2), align=False
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ def test_hausdorff_distance(self):
+ for geom, geom2 in self.pairs:
+ # Skip pairs with empty geometries — Sedona returns 0.0 instead of
NaN
+ if any(g.is_empty for g in geom) or any(g.is_empty for g in geom2):
+ continue
+
Review Comment:
Correction: my previous reply was wrong. Empty geometries DO work in Sedona
GeoSeries — the failures I observed were caused by a stale JAR (pre-PR #2730
fix). All skips have been removed in 2d1b4ac. The match tests now include empty
geometries and pass.
##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -1285,6 +1285,100 @@ def test_relate(self):
)
self.check_pd_series_equal(sgpd_result, gpd_result)
+ def test_frechet_distance(self):
+ line_pairs = [
+ (self.linestrings, self.linestrings),
+ (self.linearrings, self.linearrings),
+ (self.linestrings, self.linearrings),
+ ]
+ for geom, geom2 in line_pairs:
+ # Skip pairs containing empty geometries
+ if any(g.is_empty for g in geom) or any(g.is_empty for g in geom2):
+ continue
+
+ sgpd_result = GeoSeries(geom).frechet_distance(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).frechet_distance(
+ gpd.GeoSeries(geom2), align=True
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).frechet_distance(
+ GeoSeries(geom2), align=False
+ )
+ gpd_result = gpd.GeoSeries(geom).frechet_distance(
+ gpd.GeoSeries(geom2), align=False
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ def test_hausdorff_distance(self):
+ for geom, geom2 in self.pairs:
+ sgpd_result = GeoSeries(geom).hausdorff_distance(
+ GeoSeries(geom2), align=True
+ )
+ gpd_result = gpd.GeoSeries(geom).hausdorff_distance(
+ gpd.GeoSeries(geom2), align=True
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).hausdorff_distance(
+ GeoSeries(geom2), align=False
+ )
+ gpd_result = gpd.GeoSeries(geom).hausdorff_distance(
+ gpd.GeoSeries(geom2), align=False
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ def test_geom_equals(self):
+ for geom, geom2 in self.pairs:
+ if self.contains_any_geom_collection(geom, geom2):
+ continue
+
+ sgpd_result = GeoSeries(geom).geom_equals(GeoSeries(geom2),
align=True)
+ gpd_result = gpd.GeoSeries(geom).geom_equals(
+ gpd.GeoSeries(geom2), align=True
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ if len(geom) == len(geom2):
+ sgpd_result = GeoSeries(geom).geom_equals(GeoSeries(geom2),
align=False)
+ gpd_result = gpd.GeoSeries(geom).geom_equals(
+ gpd.GeoSeries(geom2), align=False
+ )
+ self.check_pd_series_equal(sgpd_result, gpd_result)
+
+ def test_interpolate(self):
+ for geom in [self.linestrings, self.linearrings]:
+ # Skip empty geometries
+ non_empty = [g for g in geom if not g.is_empty]
+ if not non_empty:
+ continue
+
+ sgpd_result = GeoSeries(non_empty).interpolate(1.0)
+ gpd_result = gpd.GeoSeries(non_empty).interpolate(1.0)
+ self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+
+ sgpd_result = GeoSeries(non_empty).interpolate(0.5,
normalized=True)
+ gpd_result = gpd.GeoSeries(non_empty).interpolate(0.5,
normalized=True)
Review Comment:
Correction: my previous replies were wrong. Empty geometries work fine in
Sedona GeoSeries. The actual issues were upstream Java bugs:
- `ST_LineInterpolatePoint` crashed with `ArrayIndexOutOfBoundsException` on
empty input — fixed to return `POINT EMPTY`
- Added a `length == 0` guard in the Python layer for non-normalized mode
(as Copilot suggested)
All skips removed in 2d1b4ac.
--
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]