Copilot commented on code in PR #3135:
URL: https://github.com/apache/sedona/pull/3135#discussion_r3620306431
##########
python/sedona/spark/geopandas/geoseries.py:
##########
@@ -1156,6 +1156,73 @@ def segmentize(self, max_segment_length):
returns_geom=True,
)
+ def affine_transform(self, matrix) -> "GeoSeries":
+ invalid_matrix_types = (
+ str,
+ bytes,
+ bytearray,
+ dict,
+ set,
+ frozenset,
+ PandasOnSparkSeries,
+ PandasOnSparkDataFrame,
+ pspd.Index,
+ )
+ if (
+ isinstance(matrix, invalid_matrix_types)
+ or not hasattr(matrix, "__len__")
+ or not hasattr(matrix, "__iter__")
+ ):
+ raise TypeError("'matrix' must be a local ordered sequence")
+
+ try:
+ matrix = tuple(matrix)
+ except (TypeError, ValueError) as exc:
+ raise TypeError("'matrix' must be a local ordered sequence") from
exc
+
+ if len(matrix) not in (6, 12):
+ raise ValueError("'matrix' expects either 6 or 12 coefficients")
Review Comment:
`matrix` is converted to `tuple(matrix)` before validating the length. If a
caller accidentally passes a very large sized iterable (e.g., `range(10**9)`),
this will materialize it on the driver and potentially OOM before raising the
intended `ValueError`. Since you already require `__len__`, you can validate
`len(matrix)` first and only then cast to a tuple of 6/12 items.
--
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]