spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkbrad...@apache.org
Subject spark git commit: [SPARK-10750] [ML] ML Param validate should print better error information
Date Tue, 22 Sep 2015 18:00:39 GMT
Repository: spark
Updated Branches:
  refs/heads/master f4a3c4e34 -> 7104ee0e5


[SPARK-10750] [ML] ML Param validate should print better error information

Currently when you set illegal value for params of array type (such as IntArrayParam, DoubleArrayParam,
StringArrayParam), it will throw IllegalArgumentException but with incomprehensible error
information.
Take ```VectorSlicer.setNames``` as an example:
```scala
val vectorSlicer = new VectorSlicer().setInputCol("features").setOutputCol("result")
// The value of setNames must be contain distinct elements, so the next line will throw exception.
vectorSlicer.setIndices(Array.empty).setNames(Array("f1", "f4", "f1"))
```
It will throw IllegalArgumentException as:
```
vectorSlicer_b3b4d1a10f43 parameter names given invalid value [Ljava.lang.String;798256c5.
java.lang.IllegalArgumentException: vectorSlicer_b3b4d1a10f43 parameter names given invalid
value [Ljava.lang.String;798256c5.
```
We should distinguish the value of array type from primitive type at Param.validate(value:
T), and we will get better error information.
```
vectorSlicer_3b744ea277b2 parameter names given invalid value [f1,f4,f1].
java.lang.IllegalArgumentException: vectorSlicer_3b744ea277b2 parameter names given invalid
value [f1,f4,f1].
```

Author: Yanbo Liang <ybliang8@gmail.com>

Closes #8863 from yanboliang/spark-10750.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/7104ee0e
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/7104ee0e
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/7104ee0e

Branch: refs/heads/master
Commit: 7104ee0e5dc1290b8b845a0a8ddcdb1875cfd060
Parents: f4a3c4e
Author: Yanbo Liang <ybliang8@gmail.com>
Authored: Tue Sep 22 11:00:33 2015 -0700
Committer: Joseph K. Bradley <joseph@databricks.com>
Committed: Tue Sep 22 11:00:33 2015 -0700

----------------------------------------------------------------------
 mllib/src/main/scala/org/apache/spark/ml/param/params.scala | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/7104ee0e/mllib/src/main/scala/org/apache/spark/ml/param/params.scala
----------------------------------------------------------------------
diff --git a/mllib/src/main/scala/org/apache/spark/ml/param/params.scala b/mllib/src/main/scala/org/apache/spark/ml/param/params.scala
index de32b72..48f6269 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/param/params.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/param/params.scala
@@ -65,7 +65,12 @@ class Param[T](val parent: String, val name: String, val doc: String, val
isVali
    */
   private[param] def validate(value: T): Unit = {
     if (!isValid(value)) {
-      throw new IllegalArgumentException(s"$parent parameter $name given invalid value $value.")
+      val valueToString = value match {
+        case v: Array[_] => v.mkString("[", ",", "]")
+        case _ => value.toString
+      }
+      throw new IllegalArgumentException(
+        s"$parent parameter $name given invalid value $valueToString.")
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org


Mime
View raw message