shunping commented on code in PR #35884: URL: https://github.com/apache/beam/pull/35884#discussion_r2285131133
########## sdks/python/apache_beam/ml/anomaly/detectors/pyod_adapter.py: ########## @@ -86,24 +110,36 @@ def run_inference( return _convert_to_result(batch, predictions, model_id=self._model_uri) -class PyODFactory(): +class PyODFactory: + """Factory helpers for creating OfflineDetector instances from PyOD models. + + The factory currently only exposes a convenience method to wrap a pickled + PyOD model into an OfflineDetector with a fixed threshold taken from the + trained model. + """ @staticmethod def create_detector(model_uri: str, **kwargs) -> OfflineDetector: """A utility function to create OfflineDetector for a PyOD model. - **NOTE:** This API and its implementation are currently under active - development and may not be backward compatible. + **NOTE:** This API and its implementation are currently under active + development and may not be backward compatible. + + Args: + model_uri: The URI specifying the location of the pickled + PyOD model. + **kwargs: Additional keyword arguments. + """ + model_handler = ( + KeyedModelHandler( + PyODModelHandler(model_uri=model_uri)).with_postprocess_fn( + OfflineDetector.score_prediction_adapter)) - Args: - model_uri: The URI specifying the location of the pickled PyOD model. - **kwargs: Additional keyword arguments. - """ - model_handler = KeyedModelHandler( - PyODModelHandler(model_uri=model_uri)).with_postprocess_fn( - OfflineDetector.score_prediction_adapter) m = model_handler.load_model() - assert (isinstance(m, PyODBaseDetector)) + assert isinstance(m, PyODBaseDetector) threshold = float(m.threshold_) + detector = OfflineDetector( - model_handler, threshold_criterion=FixedThreshold(threshold), **kwargs) # type: ignore[arg-type] + model_handler, threshold_criterion=FixedThreshold(threshold), **kwargs Review Comment: Looks like the change here is causing linter error. -- 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