-
Notifications
You must be signed in to change notification settings - Fork 745
[GH-2485] Implement minimum_bounding_circle #2488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GH-2485] Implement minimum_bounding_circle #2488
Conversation
petern48
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you follow existing patterns, and things fail unexpectedly, it is totally fine to ask for help. Just be a bit more patient waiting for a reply because I (and most people) have very busy lives.
Having AI agent mode go crazy making super odd changes, is more likely to make your PR take longer to merge. I (and most reviewers) don't just care about tests passing, but also about code readability. Rule of thumb: if the generated code is harder for you to understand than the original, than it probably isn't a good one.
In honesty, I think we should revert this entire last commit, you're farther off now then you originally were. Your initial commit looked great. Just needed a bit of tweaking, which I'll point you in the right direction.
| @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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to follow the Geopandas API. Here's the docs 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.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally get it. Sorry for making these a little complicated. I'll try my best to make it simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you had before is what we're looking for. Just need to add parentheses () to the end of the call to minimum_bounding_circle.
df_result = s.to_geoframe().minimum_bounding_circle()
self.check_sgpd_equals_gpd(df_result, gpd_res)
Thank you for the feedback and for taking the time to review this. I completely understand your point and appreciate the guidance. I’ll revert the last commit and go back to the earlier version so we can refine it from there. |
|
Now, let's address the CI failure of your original commit. The reality is that the issue was in the test itself. I could explain why it was causing problems, but honestly it's a little complicated. # 2) Coverage parity — compare only where inputs are valid for both backends
nonnull_nonempty_ps = (gs_in.isna() == False) & (gs_in.is_empty == False)Instead, I'd like you take a step back and rewrite the test. Don't overthink it. You honestly really don't need to understand Sedona as a project much to contribute these Geopandas functions. A lot of it is just copy-paste and following patterns. Now I'll ask you to do this:
sedona/python/tests/geopandas/test_match_geopandas_series.py Lines 721 to 725 in 762d6f8
If you're still confused, you're welcome to ask for help. We might need to make some small adjustments to make things pass, but this is a lot closer to what our desired end result is. |
|
Excellent, thanks for the direction. I'll check this. |
@petern48 Thanks for the great suggestion! I tried a similar approach to what’s used in the centroid test. The above test fails because the tolerance level in the check_sgpd_equals_gpd method is currently set to 1e-2. No rush ! Please take your time to reply. |
Yes! Now we're on the right track. I'll explain the code a little more just for your knowledge,
Nice job figuring this out. I think the best way to move forward is to add a parameter to the test function and overwrite the tolerance to use 0.5 instead just for @classmethod
def check_sgpd_equals_gpd(
cls,
actual: GeoSeries,
expected: gpd.GeoSeries,
+ tolerance: float = 1e-2
):
...
for a, e in zip(sgpd_result, expected):
...
cls.assert_geometry_almost_equal(
- a, e, tolerance=1e-2 # 1e-2
+ a, e, tolerance
)
...Then you can call it |
Awesome, that’s one of the best explanations I’ve ever received ! |
petern48
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a one last minor nit to address.
Now that we slowed down to spend a bit more time for you understand a few aspects of the code, you'll (hopefully) be better prepared to contribute more functions 😉
Co-authored-by: Peter Nguyen <petern0408@gmail.com>
Absolutely! I really appreciate you taking the time to walk me through the details. It definitely helped me understand things better and feel more confident about contributing further. |
|
Thanks @chay0112! |
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes Geopandas: Implement minimum_bounding_circle #2485What changes were proposed in this PR?
How was this patch tested?
Did this PR include necessary documentation updates?