-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-7388][SPARK-7383] wrapper for VectorAssembler in Python #5930
Changes from 3 commits
7f7ea2a
39ecb07
99c2ebf
c81072d
c221db9
73e745f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import java.util.NoSuchElementException | |
|
||
import scala.annotation.varargs | ||
import scala.collection.mutable | ||
import scala.reflect.ClassTag | ||
|
||
import org.apache.spark.annotation.AlphaComponent | ||
import org.apache.spark.ml.util.Identifiable | ||
|
@@ -218,6 +219,22 @@ class BooleanParam(parent: Params, name: String, doc: String) // No need for isV | |
override def w(value: Boolean): ParamPair[Boolean] = super.w(value) | ||
} | ||
|
||
/** Specialized version of [[Param[Array[T]]]] for Java. */ | ||
class ArrayParam[T : ClassTag]( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having |
||
parent: Params, | ||
name: String, | ||
doc: String, | ||
isValid: Array[T] => Boolean) | ||
extends Param[Array[T]](parent, name, doc, isValid) { | ||
|
||
def this(parent: Params, name: String, doc: String) = | ||
this(parent, name, doc, ParamValidators.alwaysTrue) | ||
|
||
override def w(value: Array[T]): ParamPair[Array[T]] = super.w(value) | ||
|
||
private[param] def wCast(value: Seq[T]): ParamPair[Array[T]] = w(value.toArray) | ||
} | ||
|
||
/** | ||
* A param amd its value. | ||
*/ | ||
|
@@ -311,7 +328,11 @@ trait Params extends Identifiable with Serializable { | |
*/ | ||
protected final def set[T](param: Param[T], value: T): this.type = { | ||
shouldOwn(param) | ||
paramMap.put(param.asInstanceOf[Param[Any]], value) | ||
if (param.isInstanceOf[ArrayParam[_]] && value.isInstanceOf[Seq[_]]) { | ||
paramMap.put(param.asInstanceOf[ArrayParam[Any]].wCast(value.asInstanceOf[Seq[Any]])) | ||
} else { | ||
paramMap.put(param.w(value)) | ||
} | ||
this | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,10 @@ def _transfer_params_to_java(self, params, java_obj): | |
paramMap = self.extractParamMap(params) | ||
for param in self.params: | ||
if param in paramMap: | ||
java_obj.set(param.name, paramMap[param]) | ||
value = paramMap[param] | ||
if isinstance(value, list): | ||
value = _jvm().PythonUtils.toSeq(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this special treatment if we overload There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have a |
||
java_obj.set(param.name, value) | ||
|
||
def _empty_java_param_map(self): | ||
""" | ||
|
@@ -126,10 +129,8 @@ class JavaTransformer(Transformer, JavaWrapper): | |
|
||
def transform(self, dataset, params={}): | ||
java_obj = self._java_obj() | ||
self._transfer_params_to_java({}, java_obj) | ||
java_param_map = self._create_java_param_map(params, java_obj) | ||
return DataFrame(java_obj.transform(dataset._jdf, java_param_map), | ||
dataset.sql_ctx) | ||
self._transfer_params_to_java(params, java_obj) | ||
return DataFrame(java_obj.transform(dataset._jdf), dataset.sql_ctx) | ||
|
||
|
||
@inherit_doc | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.