@@ -33,6 +33,9 @@ def __init__(self, java_obj=None):
3333 super (JavaWrapper , self ).__init__ ()
3434 self ._java_obj = java_obj
3535
36+ def __del__ (self ):
37+ SparkContext ._active_spark_context ._gateway .detach (self ._java_obj )
38+
3639 @classmethod
3740 def _create_from_java_class (cls , java_class , * args ):
3841 """
@@ -180,6 +183,24 @@ def __get_class(clazz):
180183 % stage_name )
181184 return py_stage
182185
186+ def copy (self , extra = None ):
187+ """
188+ Creates a copy of this instance with the same uid and some
189+ extra params. This implementation first calls Params.copy and
190+ then make a copy of the companion Java model with extra params.
191+ So both the Python wrapper and the Java model get copied.
192+
193+ :param extra: Extra parameters to copy to the new instance
194+ :return: Copy of this instance
195+ """
196+ if extra is None :
197+ extra = dict ()
198+ that = super (JavaParams , self ).copy (extra )
199+ if self ._java_obj is not None :
200+ that ._java_obj = self ._java_obj .copy (self ._empty_java_param_map ())
201+ that ._transfer_params_to_java ()
202+ return that
203+
183204
184205@inherit_doc
185206class JavaEstimator (JavaParams , Estimator ):
@@ -256,25 +277,3 @@ def __init__(self, java_model=None):
256277 super (JavaModel , self ).__init__ (java_model )
257278 if java_model is not None :
258279 self ._resetUid (java_model .uid ())
259-
260- def __del__ (self ):
261- if SparkContext ._gateway :
262- SparkContext ._gateway .detach (self ._java_obj )
263-
264- def copy (self , extra = None ):
265- """
266- Creates a copy of this instance with the same uid and some
267- extra params. This implementation first calls Params.copy and
268- then make a copy of the companion Java model with extra params.
269- So both the Python wrapper and the Java model get copied.
270-
271- :param extra: Extra parameters to copy to the new instance
272- :return: Copy of this instance
273- """
274- if extra is None :
275- extra = dict ()
276- that = super (JavaModel , self ).copy (extra )
277- if self ._java_obj is not None :
278- that ._java_obj = self ._java_obj .copy (self ._empty_java_param_map ())
279- that ._transfer_params_to_java ()
280- return that
0 commit comments