WeichenXu123 commented on code in PR #50199: URL: https://github.com/apache/spark/pull/50199#discussion_r1990366864
########## python/pyspark/ml/util.py: ########## @@ -185,29 +185,40 @@ def wrapped(self: "JavaWrapper", dataset: "ConnectDataFrame") -> Any: assert isinstance(self._java_obj, str) params = serialize_ml_params(self, session.client) - return ConnectDataFrame( - TransformerRelation( - child=dataset._plan, name=self._java_obj, ml_params=params, is_model=True - ), - session, + plan = TransformerRelation( + child=dataset._plan, + name=self._java_obj, + ml_params=params, + is_model=True, ) elif isinstance(self, Transformer): from pyspark.ml.connect.proto import TransformerRelation assert isinstance(self._java_obj, str) params = serialize_ml_params(self, session.client) - return ConnectDataFrame( - TransformerRelation( - child=dataset._plan, - name=self._java_obj, - ml_params=params, - uid=self.uid, - is_model=False, - ), - session, + plan = TransformerRelation( + child=dataset._plan, + name=self._java_obj, + ml_params=params, + uid=self.uid, + is_model=False, ) + else: raise RuntimeError(f"Unsupported {self}") + + # To delay the GC of the model, keep a reference to the source transformer + # in the transformed dataframe and all its descendants. + # For this case: + # + # def fit_transform(df): + # model = estimator.fit(df) + # return model.transform(df) + # + # output = fit_transform(df) + # + plan.__source_transformer__ = self # type: ignore[attr-defined] Review Comment: For model summary, it might also return Dataframe, shall we make similar change ? -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org