Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21723][ML] Fix writing LibSVM (key not found: numFeatures) - #18872
[SPARK-21723][ML] Fix writing LibSVM (key not found: numFeatures)#18872ProtD wants to merge 4 commits into
Conversation
srowen
commented
Aug 7, 2017
Better title please? |
WeichenXu123
left a comment
There was a problem hiding this comment.
Could you pls add a testcase for this fix ?
ProtD
commented
Aug 10, 2017
@srowen It worked in v2.0, but was broken probably in v2.2.0 by b3d3962. Current unit tests check writing only for dataframes which were previously read from a LibSVM format, not general ones. (And I guess people don't write LibSVMs very often - that may be why nobody has reported it.) @WeichenXu123 Yes, good idea, will do it! |
ProtD
commented
Aug 10, 2017
To reproduce the bug on v2.2 and v2.3: importorg.apache.spark.ml.linalg.VectorsvalrawData=Seq((1.0, Vectors.sparse(3, Seq((0, 2.0), (1, 3.0)))),
(4.0, Vectors.sparse(3, Seq((0, 5.0), (2, 6.0)))))
valdfTemp= spark.sparkContext.parallelize(rawData).toDF("label", "features")
dfTemp.coalesce(1).write.format("libsvm").save("...filename...")This causes |
ProtD
commented
Aug 10, 2017
I added the unit test, please review. |
HyukjinKwon
commented
Aug 10, 2017
ok to test |
SparkQA
commented
Aug 10, 2017
Test build #80508 has finished for PR 18872 at commit
|
| val rawData = new java.util.ArrayList[Row]() | ||
| rawData.add(Row(1.0, Vectors.sparse(3, Seq((0, 2.0), (1, 3.0))))) | ||
| rawData.add(Row(4.0, Vectors.sparse(3, Seq((0, 5.0), (2, 6.0))))) | ||
There was a problem hiding this comment.
Subtle: it didn't like the whitespace on this line
SparkQA
commented
Aug 11, 2017
Test build #80533 has finished for PR 18872 at commit
|
srowen
commented
Aug 11, 2017
@ProtD this needs a JIRA or else needs to be linked to whatever one you opened, in the title |
ProtD
commented
Aug 14, 2017
@srowen Ok, I created and linked a JIRA. |
| @@ -109,14 +112,15 @@ class LibSVMRelationSuite extends SparkFunSuite with MLlibTestSparkContext { | |||
| test("write libsvm data and read it again") { | |||
| val df = spark.read.format("libsvm").load(path) | |||
| val tempDir2 = new File(tempDir, "read_write_test") | |||
There was a problem hiding this comment.
I suggest the temp dir name to be Identifiable.randomUID("read_write_test"). Avoid conflicts with other parallel running tests.
There was a problem hiding this comment.
Utils.createTempDir seems to be a nicer way. The directory is automatically deleted when VM shuts down, so I believe no manual cleanup (cf. comment below) is needed.
| val df = spark.read.format("libsvm").load(path) | ||
| val tempDir2 = new File(tempDir, "read_write_test") | ||
| val writepath = tempDir2.toURI.toString | ||
| val writePath = tempDir2.toURI.toString |
| val row1 = df2.first() | ||
| val v = row1.getAs[SparseVector](1) | ||
| assert(v == Vectors.sparse(6, Seq((0, 1.0), (2, 2.0), (4, 3.0)))) | ||
| Utils.deleteRecursively(tempDir2) |
There was a problem hiding this comment.
You can remove this cleanup I think. The test framework will clean temp dir automatically I think.
SparkQA
commented
Aug 15, 2017
Test build #80676 has finished for PR 18872 at commit
|
Check the option "numFeatures" only when reading LibSVM, not when writing. When writing, Spark was raising an exception. After the change it will ignore the option completely. liancheng HyukjinKwon (Maybe the usage should be forbidden when writing, in a major version change?). Manual test, that loading and writing LibSVM files work fine, both with and without the numFeatures option. Please review http://spark.apache.org/contributing.html before opening a pull request. Author: Jan Vrsovsky <jan.vrsovsky@firma.seznam.cz> Closes#18872 from ProtD/master. (cherry picked from commit 8321c14) Signed-off-by: Sean Owen <sowen@cloudera.com>
srowen
commented
Aug 16, 2017
Merged to master/2.2 |
Check the option "numFeatures" only when reading LibSVM, not when writing. When writing, Spark was raising an exception. After the change it will ignore the option completely. liancheng HyukjinKwon (Maybe the usage should be forbidden when writing, in a major version change?). Manual test, that loading and writing LibSVM files work fine, both with and without the numFeatures option. Please review http://spark.apache.org/contributing.html before opening a pull request. Author: Jan Vrsovsky <jan.vrsovsky@firma.seznam.cz> Closesapache#18872 from ProtD/master. (cherry picked from commit 8321c14) Signed-off-by: Sean Owen <sowen@cloudera.com>
What changes were proposed in this pull request?
Check the option "numFeatures" only when reading LibSVM, not when writing. When writing, Spark was raising an exception. After the change it will ignore the option completely. @liancheng@HyukjinKwon
(Maybe the usage should be forbidden when writing, in a major version change?).
How was this patch tested?
Manual test, that loading and writing LibSVM files work fine, both with and without the numFeatures option.
Please review http://spark.apache.org/contributing.html before opening a pull request.