Github user crackcell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17233#discussion_r105820279
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/feature/StringIndexerSuite.scala ---
    @@ -122,6 +122,86 @@ class StringIndexerSuite
         assert(output === expected)
       }
     
    +  test("StringIndexer with a string input column with NULLs") {
    +    val data: Seq[java.lang.String] = Seq("a", "b", "b", null)
    +    val data2: Seq[java.lang.String] = Seq("a", "b", null)
    +    val expectedSkip = Array(1.0, 0.0)
    +    val expectedKeep = Array(1.0, 0.0, 2.0)
    +    val df = data.toDF("label")
    +    val df2 = data2.toDF("label")
    +
    +    val indexer = new StringIndexer()
    +      .setInputCol("label")
    +      .setOutputCol("labelIndex")
    +
    +    withClue("StringIndexer should throw error when setHandleValid=error 
when given NULL values") {
    +      intercept[SparkException] {
    +        indexer.setHandleInvalid("error")
    +        indexer.fit(df).transform(df2).collect()
    +      }
    +    }
    +
    +    indexer.setHandleInvalid("skip")
    +    val transformedSkip = indexer.fit(df).transform(df2)
    +    val attrSkip = Attribute
    +      .fromStructField(transformedSkip.schema("labelIndex"))
    +      .asInstanceOf[NominalAttribute]
    +    assert(attrSkip.values.get === Array("b", "a"))
    +    assert(transformedSkip.select("labelIndex").rdd.map { r =>
    +      r.getDouble(0)
    +    }.collect() === expectedSkip)
    +
    +    indexer.setHandleInvalid("keep")
    +    val transformedKeep = indexer.fit(df).transform(df2)
    +    val attrKeep = Attribute
    +      .fromStructField(transformedKeep.schema("labelIndex"))
    +      .asInstanceOf[NominalAttribute]
    +    assert(attrKeep.values.get === Array("b", "a", "__unknown"))
    +    assert(transformedKeep.select("labelIndex").rdd.map { r =>
    +      r.getDouble(0)
    +    }.collect() === expectedKeep)
    +  }
    +
    +  test("StringIndexer with a numeric input column with NULLs") {
    --- End diff --
    
    OK, I'll remove the numeric test.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to