shunping commented on code in PR #35884:
URL: https://github.com/apache/beam/pull/35884#discussion_r2282671738


##########
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
+
+    np_batch = [np.fromiter(_flatten_row(row), dtype=np.float64) for row in 
batch]

Review Comment:
   This line is too long and causing tests on linter and formatter failed. 
   
   Could you make the following change?
   
   -    np_batch = [np.fromiter(_flatten_row(row), dtype=np.float64) for row in 
batch]
   +    np_batch = [
   +        np.fromiter(_flatten_row(row), dtype=np.float64) for row in batch
   +    ]



##########
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
+
+    np_batch = [np.fromiter(_flatten_row(row), dtype=np.float64) for row in 
batch]

Review Comment:
   This line is too long and causing tests on linter and formatter failed. 
   
   Could you make the following change?
   
   ```python
   -    np_batch = [np.fromiter(_flatten_row(row), dtype=np.float64) for row in 
batch]
   +    np_batch = [
   +        np.fromiter(_flatten_row(row), dtype=np.float64) for row in batch
   +    ]
   ```



-- 
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