diff options
author | MechCoder <manojkumarsivaraj334@gmail.com> | 2015-06-30 10:27:29 -0700 |
---|---|---|
committer | Xiangrui Meng <meng@databricks.com> | 2015-06-30 10:27:29 -0700 |
commit | 5fa0863626aaf5a9a41756a0b1ec82bddccbf067 (patch) | |
tree | c8844bf78757fff102b41d7dac58bfaee988071a /python/pyspark/ml/wrapper.py | |
parent | 45281664e0d3b22cd63660ca8ad6dd574f10e21f (diff) | |
download | spark-5fa0863626aaf5a9a41756a0b1ec82bddccbf067.tar.gz spark-5fa0863626aaf5a9a41756a0b1ec82bddccbf067.tar.bz2 spark-5fa0863626aaf5a9a41756a0b1ec82bddccbf067.zip |
[SPARK-8679] [PYSPARK] [MLLIB] Default values in Pipeline API should be immutable
It might be dangerous to have a mutable as value for default param. (http://stackoverflow.com/a/11416002/1170730)
e.g
def func(example, f={}):
f[example] = 1
return f
func(2)
{2: 1}
func(3)
{2:1, 3:1}
mengxr
Author: MechCoder <manojkumarsivaraj334@gmail.com>
Closes #7058 from MechCoder/pipeline_api_playground and squashes the following commits:
40a5eb2 [MechCoder] copy
95f7ff2 [MechCoder] [SPARK-8679] [PySpark] [MLlib] Default values in Pipeline API should be immutable
Diffstat (limited to 'python/pyspark/ml/wrapper.py')
-rw-r--r-- | python/pyspark/ml/wrapper.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/python/pyspark/ml/wrapper.py b/python/pyspark/ml/wrapper.py index 7b0893e2cd..253705bde9 100644 --- a/python/pyspark/ml/wrapper.py +++ b/python/pyspark/ml/wrapper.py @@ -166,7 +166,7 @@ class JavaModel(Model, JavaTransformer): self._java_obj = java_model self.uid = java_model.uid() - def copy(self, extra={}): + def copy(self, extra=None): """ Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and @@ -175,6 +175,8 @@ class JavaModel(Model, JavaTransformer): :param extra: Extra parameters to copy to the new instance :return: Copy of this instance """ + if extra is None: + extra = dict() that = super(JavaModel, self).copy(extra) that._java_obj = self._java_obj.copy(self._empty_java_param_map()) that._transfer_params_to_java() |