jiayuasu commented on code in PR #2710:
URL: https://github.com/apache/sedona/pull/2710#discussion_r2916437656


##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -549,13 +549,24 @@ def test_is_empty(self):
             self.check_pd_series_equal(sgpd_result, gpd_result)
 
     def test_count_coordinates(self):
-        pass
+        for geom in self.geoms:
+            sgpd_result = GeoSeries(geom).count_coordinates()
+            gpd_result = gpd.GeoSeries(geom).count_coordinates()
+            self.check_pd_series_equal(sgpd_result, gpd_result)
 
     def test_count_geometries(self):
-        pass
+        for geom in self.geoms:
+            sgpd_result = GeoSeries(geom).count_geometries()
+            gpd_result = gpd.GeoSeries(geom).count_geometries()
+            self.check_pd_series_equal(sgpd_result, gpd_result)
 
     def test_count_interior_rings(self):
-        pass
+        # Sedona returns null for empty geometries while geopandas returns 0,
+        # so we only test with non-empty polygons.
+        geom = [self.polygons[1], self.polygons[2]]
+        sgpd_result = GeoSeries(geom).count_interior_rings()
+        gpd_result = gpd.GeoSeries(geom).count_interior_rings()
+        self.check_pd_series_equal(sgpd_result, gpd_result)
 

Review Comment:
   Fixed in ce5e1a8. The implementation now uses 
`F.coalesce(ST_NumInteriorRings(...), F.lit(0))` to return 0 for non-polygon 
geometries, matching geopandas semantics. The match test now runs against all 
geometry types instead of only non-empty polygons.



##########
python/sedona/spark/geopandas/base.py:
##########
@@ -313,14 +313,94 @@ def is_empty(self):
         """
         return _delegate_to_geometry_column("is_empty", self)
 
-    # def count_coordinates(self):
-    #     raise NotImplementedError("This method is not implemented yet.")
+    def count_coordinates(self):
+        """Return a ``Series`` of ``dtype('int64')`` with the number of
+        coordinate tuples in each geometry.
 

Review Comment:
   Fixed in ce5e1a8. Updated docstrings to use `dtype: int32` which matches 
Spark's IntegerType.



##########
python/sedona/spark/geopandas/base.py:
##########
@@ -313,14 +313,94 @@ def is_empty(self):
         """
         return _delegate_to_geometry_column("is_empty", self)
 
-    # def count_coordinates(self):
-    #     raise NotImplementedError("This method is not implemented yet.")
+    def count_coordinates(self):
+        """Return a ``Series`` of ``dtype('int64')`` with the number of
+        coordinate tuples in each geometry.
 
-    # def count_geometries(self):
-    #     raise NotImplementedError("This method is not implemented yet.")
+        Returns
+        -------
+        Series (int)
 
-    # def count_interior_rings(self):
-    #     raise NotImplementedError("This method is not implemented yet.")
+        Examples
+        --------
+        >>> from sedona.spark.geopandas import GeoSeries
+        >>> from shapely.geometry import Point, LineString, Polygon
+        >>> s = GeoSeries(
+        ...     [
+        ...         Point(0, 0),
+        ...         LineString([(0, 0), (1, 1), (2, 2)]),
+        ...         Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]),
+        ...     ]
+        ... )
+        >>> s.count_coordinates()
+        0    1
+        1    3
+        2    5
+        dtype: int64
+
+        """
+        return _delegate_to_geometry_column("count_coordinates", self)
+
+    def count_geometries(self):
+        """Return a ``Series`` of ``dtype('int64')`` with the number of
+        geometries in each multi-geometry or geometry collection.
+
+        For non-multi geometries, returns 1.
+
+        Returns
+        -------
+        Series (int)
+
+        Examples
+        --------
+        >>> from sedona.spark.geopandas import GeoSeries
+        >>> from shapely.geometry import Point, MultiPoint, MultiLineString
+        >>> s = GeoSeries(
+        ...     [
+        ...         Point(0, 0),
+        ...         MultiPoint([(0, 0), (1, 1)]),
+        ...         MultiLineString([[(0, 0), (1, 1)], [(2, 2), (3, 3)]]),
+        ...     ]
+        ... )
+        >>> s.count_geometries()
+        0    1
+        1    2
+        2    2
+        dtype: int64
+
+        """
+        return _delegate_to_geometry_column("count_geometries", self)
+
+    def count_interior_rings(self):
+        """Return a ``Series`` of ``dtype('int64')`` with the number of
+        interior rings (holes) in each polygon geometry.
+
+        Returns 0 for polygons without holes and for non-polygon geometries.
+

Review Comment:
   Fixed in ce5e1a8. The implementation now wraps with 
`F.coalesce(ST_NumInteriorRings(...), F.lit(0))` so non-polygon geometries 
return 0, matching the docstring and geopandas semantics.



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