Skip to content

Commit 24697f3

Browse files
committed
add no element test
1 parent f34da1f commit 24697f3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

mllib/src/test/scala/org/apache/spark/ml/stat/SummarizerSuite.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
package org.apache.spark.ml.stat
1919

20-
import org.scalatest.exceptions.TestFailedException
21-
22-
import org.apache.spark.SparkFunSuite
20+
import org.apache.spark.{SparkException, SparkFunSuite}
2321
import org.apache.spark.ml.linalg.{Vector, Vectors}
2422
import org.apache.spark.ml.util.TestingUtils._
2523
import org.apache.spark.mllib.linalg.{Vector => OldVector, Vectors => OldVectors}
2624
import org.apache.spark.mllib.stat.{MultivariateOnlineSummarizer, Statistics}
2725
import org.apache.spark.mllib.util.MLlibTestSparkContext
28-
import org.apache.spark.sql.{DataFrame, Row}
26+
import org.apache.spark.sql.Row
2927

3028
class SummarizerSuite extends SparkFunSuite with MLlibTestSparkContext {
3129

@@ -203,6 +201,16 @@ class SummarizerSuite extends SparkFunSuite with MLlibTestSparkContext {
203201
}
204202
}
205203

204+
test("no element") {
205+
val df = Seq[Tuple1[Vector]]().toDF("features")
206+
val c = df.col("features")
207+
intercept[SparkException] {
208+
df.select(metrics("mean").summary(c), mean(c)).first()
209+
}
210+
compareRow(df.select(metrics("count").summary(c), count(c)).first(),
211+
Row(Row(0L), 0L))
212+
}
213+
206214
val singleElem = Vectors.dense(0.0, 1.0, 2.0)
207215
testExample("single element", Seq((singleElem, 2.0)),
208216
ExpectedMetrics(

0 commit comments

Comments
 (0)