petern48 commented on code in PR #2455:
URL: https://github.com/apache/sedona/pull/2455#discussion_r2464152410


##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1954,6 +1954,83 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        s = GeoSeries(
+            [
+                Point(0, 0),
+                Point(0, 0),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        s2 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        # "ABCDEFGHI" DE-9 Format
+        # A Dimension of intersection
+        # B Dimension of interior intersection
+        # C Dimension of boundary intersection
+        # D Interior of first geometry intersects exterior of second
+        # E Exterior of first geometry intersects interior of second
+        # F Boundary of first geometry intersects exterior of second
+        # G Exterior of first geometry intersects boundary of second
+        # H Exterior of first geometry intersects exterior of second
+        # I Dimension of intersection for interiors
+        # 0 = false, 1 = point, 2 = line, F = area
+
+        # 1. Test with single geometry
+        point = Point(0, 0)
+        result = s.relate(point)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2", "FF10F0FF2"])
+        assert_series_equal(result.to_pandas(), expected)

Review Comment:
   ```suggestion
           self.check_pd_series_equal(result, expected)
   ```
   
   While this works, it's actually preferred to use 
`self.check_pd_series_equal()` instead. You can read about why in this issue: 
https://github.com/apache/sedona/issues/2379.



##########
python/sedona/spark/geopandas/geoseries.py:
##########
@@ -79,6 +79,7 @@
         "is_valid_reason",
         "length",
         "make_valid",
+        "relate",

Review Comment:
   Just an fyi, we don't actually keep this list updated (in fact, I just filed 
an [issue](https://github.com/apache/sedona/pull/2455) to remove this). It 
doesn't hurt to update it, so it's fine to leave this change here.



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1954,6 +1954,83 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        s = GeoSeries(
+            [
+                Point(0, 0),
+                Point(0, 0),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        s2 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        # "ABCDEFGHI" DE-9 Format
+        # A Dimension of intersection
+        # B Dimension of interior intersection
+        # C Dimension of boundary intersection
+        # D Interior of first geometry intersects exterior of second
+        # E Exterior of first geometry intersects interior of second
+        # F Boundary of first geometry intersects exterior of second
+        # G Exterior of first geometry intersects boundary of second
+        # H Exterior of first geometry intersects exterior of second
+        # I Dimension of intersection for interiors
+        # 0 = false, 1 = point, 2 = line, F = area
+
+        # 1. Test with single geometry
+        point = Point(0, 0)
+        result = s.relate(point)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2", "FF10F0FF2"])
+        assert_series_equal(result.to_pandas(), expected)
+
+        result = s.relate(s2)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(result.to_pandas(), expected)

Review Comment:
   ```suggestion
           self.check_pd_series_equal(result, expected)
   ```



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1954,6 +1954,83 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        s = GeoSeries(
+            [
+                Point(0, 0),
+                Point(0, 0),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        s2 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        # "ABCDEFGHI" DE-9 Format
+        # A Dimension of intersection
+        # B Dimension of interior intersection
+        # C Dimension of boundary intersection
+        # D Interior of first geometry intersects exterior of second
+        # E Exterior of first geometry intersects interior of second
+        # F Boundary of first geometry intersects exterior of second
+        # G Exterior of first geometry intersects boundary of second
+        # H Exterior of first geometry intersects exterior of second
+        # I Dimension of intersection for interiors
+        # 0 = false, 1 = point, 2 = line, F = area
+
+        # 1. Test with single geometry
+        point = Point(0, 0)
+        result = s.relate(point)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2", "FF10F0FF2"])
+        assert_series_equal(result.to_pandas(), expected)
+
+        result = s.relate(s2)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(result.to_pandas(), expected)
+        # 2. Test with align=True (different indices)
+        s3 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(1, 3),
+        )
+        s4 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(0, 2),
+        )
+        result = s3.relate(s4, align=True)
+        expected = pd.Series([None, "FF0FFF0F2", None], index=[0, 1, 2])
+        assert_series_equal(result.to_pandas(), expected)
+
+        # 3. Test with align=False
+        result = s3.relate(s4, align=False)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2"], index=range(1, 3))
+        assert_series_equal(result.to_pandas(), expected)
+
+        # 4. Check that GeoDataFrame works too
+        df_result = s.to_geoframe().relate(s2, align=False)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(df_result.to_pandas(), expected)

Review Comment:
   ```suggestion
           self.check_pd_series_equal(result, expected)
   ```



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1954,6 +1954,83 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        s = GeoSeries(
+            [
+                Point(0, 0),
+                Point(0, 0),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        s2 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        # "ABCDEFGHI" DE-9 Format
+        # A Dimension of intersection
+        # B Dimension of interior intersection
+        # C Dimension of boundary intersection
+        # D Interior of first geometry intersects exterior of second
+        # E Exterior of first geometry intersects interior of second
+        # F Boundary of first geometry intersects exterior of second
+        # G Exterior of first geometry intersects boundary of second
+        # H Exterior of first geometry intersects exterior of second
+        # I Dimension of intersection for interiors
+        # 0 = false, 1 = point, 2 = line, F = area
+
+        # 1. Test with single geometry
+        point = Point(0, 0)
+        result = s.relate(point)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2", "FF10F0FF2"])
+        assert_series_equal(result.to_pandas(), expected)
+
+        result = s.relate(s2)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(result.to_pandas(), expected)
+        # 2. Test with align=True (different indices)
+        s3 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(1, 3),
+        )
+        s4 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(0, 2),
+        )
+        result = s3.relate(s4, align=True)
+        expected = pd.Series([None, "FF0FFF0F2", None], index=[0, 1, 2])
+        assert_series_equal(result.to_pandas(), expected)
+
+        # 3. Test with align=False
+        result = s3.relate(s4, align=False)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2"], index=range(1, 3))
+        assert_series_equal(result.to_pandas(), expected)

Review Comment:
   ```suggestion
           self.check_pd_series_equal(result, expected)
   ```



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1954,6 +1954,83 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        s = GeoSeries(
+            [
+                Point(0, 0),
+                Point(0, 0),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        s2 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        # "ABCDEFGHI" DE-9 Format
+        # A Dimension of intersection
+        # B Dimension of interior intersection
+        # C Dimension of boundary intersection
+        # D Interior of first geometry intersects exterior of second
+        # E Exterior of first geometry intersects interior of second
+        # F Boundary of first geometry intersects exterior of second
+        # G Exterior of first geometry intersects boundary of second
+        # H Exterior of first geometry intersects exterior of second
+        # I Dimension of intersection for interiors
+        # 0 = false, 1 = point, 2 = line, F = area
+
+        # 1. Test with single geometry
+        point = Point(0, 0)
+        result = s.relate(point)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2", "FF10F0FF2"])
+        assert_series_equal(result.to_pandas(), expected)
+
+        result = s.relate(s2)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(result.to_pandas(), expected)
+        # 2. Test with align=True (different indices)
+        s3 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(1, 3),
+        )
+        s4 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(0, 2),
+        )
+        result = s3.relate(s4, align=True)
+        expected = pd.Series([None, "FF0FFF0F2", None], index=[0, 1, 2])
+        assert_series_equal(result.to_pandas(), expected)

Review Comment:
   ```suggestion
           self.check_pd_series_equal(result, expected)
   ```



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1954,6 +1954,83 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        s = GeoSeries(
+            [
+                Point(0, 0),
+                Point(0, 0),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        s2 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+                LineString([(0, 0), (1, 1)]),
+            ]
+        )
+        # "ABCDEFGHI" DE-9 Format
+        # A Dimension of intersection
+        # B Dimension of interior intersection
+        # C Dimension of boundary intersection
+        # D Interior of first geometry intersects exterior of second
+        # E Exterior of first geometry intersects interior of second
+        # F Boundary of first geometry intersects exterior of second
+        # G Exterior of first geometry intersects boundary of second
+        # H Exterior of first geometry intersects exterior of second
+        # I Dimension of intersection for interiors
+        # 0 = false, 1 = point, 2 = line, F = area
+
+        # 1. Test with single geometry
+        point = Point(0, 0)
+        result = s.relate(point)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2", "FF10F0FF2"])
+        assert_series_equal(result.to_pandas(), expected)
+
+        result = s.relate(s2)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(result.to_pandas(), expected)
+        # 2. Test with align=True (different indices)
+        s3 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(1, 3),
+        )
+        s4 = GeoSeries(
+            [
+                Point(0, 0),
+                Point(1, 1),
+            ],
+            index=range(0, 2),
+        )
+        result = s3.relate(s4, align=True)
+        expected = pd.Series([None, "FF0FFF0F2", None], index=[0, 1, 2])
+        assert_series_equal(result.to_pandas(), expected)
+
+        # 3. Test with align=False
+        result = s3.relate(s4, align=False)
+        expected = pd.Series(["0FFFFFFF2", "0FFFFFFF2"], index=range(1, 3))
+        assert_series_equal(result.to_pandas(), expected)
+
+        # 4. Check that GeoDataFrame works too
+        df_result = s.to_geoframe().relate(s2, align=False)
+        expected = pd.Series(["0FFFFFFF2", "FF0FFF0F2", "1FFF0FFF2"])
+        assert_series_equal(df_result.to_pandas(), expected)
+
+        # 5. touching_polygons and overlapping polygon case
+        touching_poly_a = Polygon(((0, 0), (1, 0), (1, 1), (0, 1), (0, 0)))
+        touching_poly_b = Polygon(((1, 0), (2, 0), (2, 1), (1, 1), (1, 0)))
+        overlapping_poly_a = Polygon(((0, 0), (2, 0), (2, 2), (0, 2), (0, 0)))
+        overlapping_poly_b = Polygon(((1, 1), (3, 1), (3, 3), (1, 3), (1, 1)))
+        s5 = GeoSeries([touching_poly_a, overlapping_poly_a])
+        s6 = GeoSeries([touching_poly_b, overlapping_poly_b])
+        result = s5.relate(s6)
+
+        expected = pd.Series(["FF2F11212", "212101212"])
+        assert_series_equal(result.to_pandas(), expected)

Review Comment:
   ```suggestion
           self.check_pd_series_equal(result, expected)
   ```



##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -1073,6 +1078,21 @@ def test_contains(self):
     def test_contains_properly(self):
         pass
 
+    def test_relate(self):
+        for geom, geom2 in self.pairs:
+            if self.contains_any_geom_collection(geom, geom2):
+                continue

Review Comment:
   ```suggestion
   ```
   
   This conditional skip is included in some test functions to work around a 
bug or difference in Sedona's behavior, but for this case, we can actually 
remove this, since the tests pass without it (I checked this branch out and 
tried it locally).



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