feat(helpers): accept & auto-convert ee.Geometry in fit_geometry#327
feat(helpers): accept & auto-convert ee.Geometry in fit_geometry#327abidanBrito wants to merge 8 commits into
Conversation
|
Thanks, @abidanBrito! Give me a bit of time to do a review. Note that it's expected that the build tests fail when run from a fork. I can run them once we get through any initial changes that are needed. |
Got it, thanks! I'll keep an eye out for any requested changes. |
jdbcode
left a comment
There was a problem hiding this comment.
Looks greats, thanks so much!
|
@abidanBrito, while pulling into Google the lint checker found some minor style issues. I'll commit the fixes to this PR. |
|
Thanks for catching those, @jdbcode. One thing I noticed - Running Also, may I suggest adding |
|
@abidanBrito, While reviewing and testing this internally, we had a discussion about the API design and wanted to run a proposal by you. Currently, the implementation uses duck typing (checking for We would like to propose restricting the supported types strictly to:
Why restrict it?
Proposed Implementation: We can update def _coerce_to_shapely_geometry(geometry):
if isinstance(geometry, shapely.geometry.base.BaseGeometry):
return geometry
if isinstance(geometry, ee.Geometry):
try:
return shapely.geometry.shape(geometry.getInfo())
except Exception as e:
raise TypeError("Could not convert ee.Geometry...") from e
raise TypeError("Expected shapely or ee.Geometry...")(We would also update the tests to mock or use offline ee.Geometry objects). How would you prefer to proceed?
Let us know your thoughts. |
More Files Flagged: Yes, this is expected. There are some pre-existing files in the repo that don't fully conform to the style rules (or were formatted with a different version). You don't need to fix the entire repo—please only focus on the files you modified. You can target specific files to avoid the noise, for example: Dev Dependencies & Pre-commit Hooks: Before we move forward with a PR to add a Xee & External Contributions: Because Xee is mostly in maintenance mode for us, we're happy for and appreciate external PRs! The process for importing external code into Google's internal systems is currently a bit of a challenge, but we want to get the workflow streamlined. Thank you for bearing with us. |
|
Thanks a lot for the feedback, @jdbcode! I completely agree with your points. Frankly, I tried to get smart with duck typing as a straight-forward way to avoid a hard dependency on Also, I understand the need to align with your internal tooling and standards. I've pushed the changes. Hopefully it passes this time, but feel free to make any changes you deem necessary. |
51d77b2 to
3d34e63
Compare
Closes #310
Summary
fit_geometrypreviously accepted onlyshapelygeometries. Passing anee.Geometryproduced confusing downstream errors with no hint at the expected conversion. This PR adds guarded auto-conversion for Earth Engine-like geometry inputs, with a clear, actionableTypeErrorwhen conversion isn't possible.Changes
_coerce_to_shapely_geometryhelper:shapely.geometry.shape(obj.getInfo()).TypeErrornaming the expected type along with the exact conversion snippet.fit_geometrynow acceptsUnion[shapely.geometry.base.BaseGeometry, ee.Geometry]and coerces before fitting.Design decisions
isinstance(ee.Geometry)- Conversion keys off the presence of a callablegetInfo, so we avoid a hard EE dependency in the conversion path.getInfo()runs outside thetry- Only theshapelycall is guarded; genuine EE runtime errors propagate instead of being masked as conversion failures.Testing
Added local unit tests: shapely passthrough, valid EE-like mock, invalid
getInfopayload and unrelated input type.NOTE:
docs-checkhas pre-existing nitpicky failures onmain. I believe this branch introduces no new warnings.