gemini-code-assist[bot] commented on code in PR #35884:
URL: https://github.com/apache/beam/pull/35884#discussion_r2280741406


##########
sdks/python/apache_beam/ml/anomaly/detectors/pyod_adapter.py:
##########
@@ -75,9 +75,14 @@ def run_inference(
       model: PyODBaseDetector,
       inference_args: Optional[dict[str, Any]] = None
   ) -> Iterable[PredictionResult]:
-    np_batch = []
-    for row in batch:
-      np_batch.append(np.fromiter(row, dtype=np.float64))
+    def _flatten_row(row_values):
+      for value in row_values:
+        if isinstance(value, (list, tuple, np.ndarray)):
+          yield from value
+        else:
+          yield value

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `_flatten_row` helper function is defined inside `run_inference`, which 
means it gets redefined on every call. While this is functionally correct, for 
better performance and readability, consider moving it to the module level (as 
a private function like `_flatten_row`) or making it a static method on the 
`PyODModelHandler` class. This would also make it easier to add a docstring and 
type hints for better maintainability.



-- 
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: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to