Skip to content

Commit c7ad085

Browse files
jegonzalmengxr
authored andcommitted
[SPARK-4130][MLlib] Fixing libSVM parser bug with extra whitespace
This simple patch filters out extra whitespace entries. Author: Joseph E. Gonzalez <[email protected]> Author: Joey <[email protected]> Closes apache#2996 from jegonzal/loadLibSVM and squashes the following commits: e0227ab [Joey] improving readability e028e84 [Joseph E. Gonzalez] fixing whitespace bug in loadLibSVMFile when parsing libSVM files
1 parent 6db3157 commit c7ad085

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mllib/src/main/scala/org/apache/spark/mllib/util/MLUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object MLUtils {
7676
.map { line =>
7777
val items = line.split(' ')
7878
val label = items.head.toDouble
79-
val (indices, values) = items.tail.map { item =>
79+
val (indices, values) = items.tail.filter(_.nonEmpty).map { item =>
8080
val indexAndValue = item.split(':')
8181
val index = indexAndValue(0).toInt - 1 // Convert 1-based indices to 0-based.
8282
val value = indexAndValue(1).toDouble

0 commit comments

Comments
 (0)