petern48 commented on code in PR #2488:
URL: https://github.com/apache/sedona/pull/2488#discussion_r2512747663
##########
python/sedona/spark/geopandas/geoseries.py:
##########
@@ -1030,13 +1030,14 @@ def representative_point(self):
# Implementation of the abstract method.
raise NotImplementedError("This method is not implemented yet.")
- @property
- def minimum_bounding_circle(self) -> "GeoSeries":
- spark_expr = stf.ST_MinimumBoundingCircle(self.spark.column)
- return self._query_geometry_column(
- spark_expr,
- returns_geom=True,
- )
+ def minimum_bounding_circle(self, quadrant_segments: int = None):
+ if quadrant_segments is None:
+ spark_expr = stf.ST_MinimumBoundingCircle(self.spark.column)
+ else:
+ spark_expr = stf.ST_MinimumBoundingCircle(
+ self.spark.column, quadrant_segments
+ )
+ return self._query_geometry_column(spark_expr, returns_geom=True)
Review Comment:
We want to follow the Geopandas API. Here's the
[docs](https://geopandas.org/en/v1.0.0/docs/reference/api/geopandas.GeoSeries.minimum_bounding_circle.html)
for `.minimum_bounding_circle()`. You'll see that it doesn't have a
`quadrant_segments` parameter, so we don't want to add it to our python API
either.
##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1285,43 +1285,31 @@ def test_representative_point(self):
def test_minimum_bounding_circle(self):
s = GeoSeries(
[
- Polygon([(0, 0), (2, 0), (2, 2), (0, 2)]),
- LineString([(0, 0), (3, 0)]),
- Point(1, 1),
+ Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]),
+ LineString([(0, 0), (2, 0)]),
+ Point(0, 0),
None,
]
)
- result = s.minimum_bounding_circle
-
- self.check_pd_series_equal(
- result.isna(), pd.Series([False, False, False, True])
- )
-
- gpd_res = result.to_geopandas()
- gpd_src = s.to_geopandas()
-
- non_null = gpd_res.notna()
-
- got_types = gpd_res[non_null].geom_type.reset_index(drop=True)
- exp_types = pd.Series(["Polygon", "Polygon", "Point"])
- pd.testing.assert_series_equal(
- got_types, exp_types, check_names=False, check_dtype=False
- )
+ expected = gpd.GeoSeries(
+ [
+ Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]),
+ LineString([(0, 0), (2, 0)]),
+ Point(0, 0),
+ None,
+ ]
+ ).minimum_bounding_circle()
- # Coverage: allow for tiny numeric tolerance on circle approximation
- covered = (
- gpd_res[non_null]
- .buffer(1e-9)
- .covers(gpd_src[non_null])
- .reset_index(drop=True)
- )
- pd.testing.assert_series_equal(
- covered, pd.Series([True, True, True]), check_names=False
- )
+ # GeoSeries path
+ result = s.minimum_bounding_circle()
+ self.check_sgpd_equals_gpd(result, expected)
- df_result = s.to_geoframe().minimum_bounding_circle
- self.check_sgpd_equals_gpd(df_result, gpd_res)
+ tg = getattr(s, "to_geoframe")
+ gdf = tg() if callable(tg) else tg
+ mbc = getattr(gdf, "minimum_bounding_circle")
+ df_result = mbc() if callable(mbc) else mbc
+ self.check_sgpd_equals_gpd(df_result, expected)
Review Comment:
This is unnecesssarily complicating the code's readability. Let's keep with
existing patterns. When things don't behave the way we want them to, we should
adjust things bit, not change completely different parts of the code.
--
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]