Github user yogeshg commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20724#discussion_r172273476
  
    --- Diff: python/pyspark/ml/tests.py ---
    @@ -173,6 +173,45 @@ class MockModel(MockTransformer, Model, HasFake):
         pass
     
     
    +class JavaWrapperMemoryTests(SparkSessionTestCase):
    +
    +    def test_java_object_gets_detached(self):
    +        df = self.spark.createDataFrame([(1.0, 2.0, Vectors.dense(1.0)),
    +                                         (0.0, 2.0, Vectors.sparse(1, [], 
[]))],
    +                                        ["label", "weight", "features"])
    +        lr = LinearRegression(maxIter=1, regParam=0.0, solver="normal", 
weightCol="weight",
    +                              fitIntercept=False)
    +
    +        model = lr.fit(df)
    +        summary = model.summary
    +
    +        self.assertIsInstance(model, JavaWrapper)
    +        self.assertIsInstance(summary, JavaWrapper)
    +        self.assertIsInstance(model, JavaParams)
    +        self.assertNotIsInstance(summary, JavaParams)
    +
    +        error_no_object = 'Target Object ID does not exist for this 
gateway'
    +
    +        self.assertIn("LinearRegression_", model._java_obj.toString())
    +        self.assertIn("LinearRegressionTrainingSummary", 
summary._java_obj.toString())
    +
    +        model.__del__()
    +
    +        with self.assertRaisesRegexp(py4j.protocol.Py4JError, 
error_no_object):
    +            model._java_obj.toString()
    +        self.assertIn("LinearRegressionTrainingSummary", 
summary._java_obj.toString())
    +
    +        try:
    +            summary.__del__()
    +        except:
    --- End diff --
    
    `__del__` is not a method of the object class. This test throws an error 
with earlier code (when `__del__` is in `JavaParams`) because the 
`LinearRegressionSummary` class did not inherit the del method from any of its 
ancestors (`JavaWrapper` and `object`). After moving the del method to 
`JavaWrapper` this line executes. If I remove the try method, then we are 
testing the condition that "`__del__` method exists && `__del__` method 
releases memory".


---

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

Reply via email to