Skip to content

Commit 3b1d08a

Browse files
[MLLIB][tree] merge the assertion into the evaluation of numFeatures
1 parent cf2e567 commit 3b1d08a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mllib/src/main/scala/org/apache/spark/mllib/tree/impl/DecisionTreeMetadata.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ private[tree] object DecisionTreeMetadata extends Logging {
107107
numTrees: Int,
108108
featureSubsetStrategy: String): DecisionTreeMetadata = {
109109

110-
require(!input.isEmpty, s"DecisionTree requires size of input RDD > 0, " +
111-
s"but was given by an empty one.")
112-
110+
val numFeatures = input.map(_.features.size).take(1).headOption.getOrElse {
111+
throw new IllegalArgumentException(s"DecisionTree requires size of input RDD > 0, " +
112+
s"but was given by empty one.")
113+
}
113114
val numExamples = input.count()
114-
val numFeatures = input.take(1)(0).features.size
115115
val numClasses = strategy.algo match {
116116
case Classification => strategy.numClasses
117117
case Regression => 0

0 commit comments

Comments
 (0)