hvanhovell commented on code in PR #47785:
URL: https://github.com/apache/spark/pull/47785#discussion_r1720504653
##########
mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala:
##########
@@ -189,13 +189,12 @@ class StringIndexer @Since("1.4.0") (
private def getSelectedCols(dataset: Dataset[_], inputCols: Seq[String]):
Seq[Column] = {
inputCols.map { colName =>
val col = dataset.col(colName)
- if (col.expr.dataType == StringType) {
- col
- } else {
- // We don't count for NaN values. Because `StringIndexerAggregator`
only processes strings,
- // we replace NaNs with null in advance.
- when(!isnan(col), col).cast(StringType)
- }
+ // We don't count for NaN values. Because `StringIndexerAggregator` only
processes strings,
+ // we replace NaNs with null in advance.
+ val fpTypes = Seq(DoubleType, FloatType).map(_.catalogString)
+ when(typeof(col).isin(fpTypes: _*) && isnan(col), lit(null))
Review Comment:
The optimizer will simplify this into:
- `when(isNaN(col), null).otherwise(col).cast(StringType)` for Float/Double
- `col` for String
- `col.castS(StringType)` for other datatypes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]