Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private[mllib] object NumericParser {
}
} else if (token == ")") {
parsing = false
} else if (token.trim.isEmpty){
// ignore whitespaces between delim chars, e.g. ", ["
} else {
// expecting a number
items.append(parseDouble(token))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class LabeledPointSuite extends SparkFunSuite {
}
}

test("parse labeled points with whitespaces") {
val point = LabeledPoint.parse("(0.0, [1.0, 2.0])")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, doesn't this still yield " 2.0" as a token during parsing? which wouldn't parse I'd imagine. Does this pass? in which case I'm missing something ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it comes to java.lang.Double.parseDouble(s) it ignores spaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting. Sounds good.

assert(point === LabeledPoint(0.0, Vectors.dense(1.0, 2.0)))
}

test("parse labeled points with v0.9 format") {
val point = LabeledPoint.parse("1.0,1.0 0.0 -2.0")
assert(point === LabeledPoint(1.0, Vectors.dense(1.0, 0.0, -2.0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ class NumericParserSuite extends SparkFunSuite {
}
}
}

test("parser with whitespaces") {
val s = "(0.0, [1.0, 2.0])"
val parsed = NumericParser.parse(s).asInstanceOf[Seq[_]]
assert(parsed(0).asInstanceOf[Double] === 0.0)
assert(parsed(1).asInstanceOf[Array[Double]] === Array(1.0, 2.0))
}
}