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

    https://github.com/apache/spark/pull/17233#discussion_r105721463
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala ---
    @@ -188,35 +189,45 @@ class StringIndexerModel (
         transformSchema(dataset.schema, logging = true)
     
         val filteredLabels = getHandleInvalid match {
    -      case StringIndexer.KEEP_UNSEEN_LABEL => labels :+ "__unknown"
    +      case StringIndexer.KEEP_INVALID => labels :+ "__unknown"
           case _ => labels
         }
     
         val metadata = NominalAttribute.defaultAttr
           .withName($(outputCol)).withValues(filteredLabels).toMetadata()
         // If we are skipping invalid records, filter them out.
         val (filteredDataset, keepInvalid) = getHandleInvalid match {
    -      case StringIndexer.SKIP_UNSEEN_LABEL =>
    +      case StringIndexer.SKIP_INVALID =>
             val filterer = udf { label: String =>
               labelToIndex.contains(label)
             }
    -        (dataset.where(filterer(dataset($(inputCol)))), false)
    -      case _ => (dataset, getHandleInvalid == 
StringIndexer.KEEP_UNSEEN_LABEL)
    +        
(dataset.na.drop(Array($(inputCol))).where(filterer(dataset($(inputCol)))), 
false)
    +      case _ => (dataset, getHandleInvalid == StringIndexer.KEEP_INVALID)
         }
     
    -    val indexer = udf { label: String =>
    -      if (labelToIndex.contains(label)) {
    -        labelToIndex(label)
    -      } else if (keepInvalid) {
    -        labels.length
    +    val indexer = udf { row: Row =>
    --- End diff --
    
    No need to use a Row; just take a String:
    ```
        val indexer = udf { label: String =>
          if (label == null) {
            if (keepInvalid) {
              labels.length
            } else {
              throw new SparkException("StringIndexer encountered NULL value. 
To handle or skip " +
                "NULLS, try setting StringIndexer.handleInvalid.")
            }
          } else {
            if (labelToIndex.contains(label)) {
              labelToIndex(label)
            } else if (keepInvalid) {
              labels.length
            } else {
              throw new SparkException(s"Unseen label: $label.  To handle 
unseen labels, " +
                s"set Param handleInvalid to ${StringIndexer.KEEP_INVALID}.")
            }
          }
        }
    ```


---
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