srowen commented on a change in pull request #23676: [SPARK-26754][PYTHON] Add 
hasTrainingSummary to replace duplicate code in PySpark
URL: https://github.com/apache/spark/pull/23676#discussion_r252307136
 
 

 ##########
 File path: python/pyspark/ml/util.py
 ##########
 @@ -611,3 +611,33 @@ def loadParamsInstance(path, sc):
         py_type = DefaultParamsReader.__get_class(pythonClassName)
         instance = py_type.load(path)
         return instance
+
+
+@inherit_doc
+class HasTrainingSummary(object):
+    """
+    Base class for models that provides Training summary.
+    .. versionadded:: 3.0.0
+    """
+
+    @property
+    @since("3.0.0")
+    def hasSummary(self):
+        """
+        Indicates whether a training summary exists for this model
+        instance.
+        """
+        return self._call_java("hasSummary")
+
+    @property
+    @since("3.0.0")
+    def summary(self):
+        """
+        Gets summary of the model trained on the training set. An exception is 
thrown if
+        no summary exists.
+        """
+        if self.hasSummary:
 
 Review comment:
   You could also call "summary" directly though I suppose that would result in 
a different, possibly less useful error. I was also wondering whether 
RuntimeError is the right one, but I see other call sites above throw this when 
there is no summary.
   
   Can you remove other checks for "if self.hasSummary" then, above? because 
when summary() is called it will now throw this error already.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to