shunping commented on code in PR #34286: URL: https://github.com/apache/beam/pull/34286#discussion_r1995737572
########## sdks/python/apache_beam/ml/anomaly/detectors/custom.py: ########## @@ -0,0 +1,229 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import typing +from typing import Any +from typing import Callable +from typing import Dict +from typing import Optional +from typing import SupportsFloat + +import numpy +import pandas + +import apache_beam as beam +from apache_beam.ml.anomaly.base import AnomalyDetector +from apache_beam.ml.anomaly.specifiable import specifiable +from apache_beam.ml.inference.base import KeyedModelHandler +from apache_beam.ml.inference.base import ModelHandler +from apache_beam.ml.inference.base import PredictionResult + +# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports +try: + import torch +except ImportError: + torch = None + +try: + import tensorflow as tf +except ImportError: + tf = None + + +def _to_numpy_array(row: beam.Row): + """Converts an Apache Beam Row to a NumPy array.""" + return numpy.array(list(row)) Review Comment: I agree with you that it will be much simpler to only support `ModelHandler[beam.Row, float]`, but I am also hesitating to put all the adapter burden to users, which could be a friction of adapting the new transform. With that said, I think instead of putting those functions in the SDK, maybe we can show them in examples later. WDYT? -- 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