You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/12/03 05:58:10 UTC

[GitHub] [spark] dongjoon-hyun commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs

dongjoon-hyun commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
URL: https://github.com/apache/spark/pull/26738#discussion_r352996206
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala
 ##########
 @@ -456,11 +456,23 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
     val keyExpr = df.col(col.name).expr
     def buildExpr(v: Any) = Cast(Literal(v), keyExpr.dataType)
     val branches = replacementMap.flatMap { case (source, target) =>
-      Seq(buildExpr(source), buildExpr(target))
+      if (isNaN(source) || isNaN(target)) {
+        col.dataType match {
+          case IntegerType | LongType | ShortType | ByteType => Seq.empty
 
 Review comment:
   Thank you for making a PR and I fully understand this issue, @johnhany97 .
   
   One concern is that the current behavior is consistent with Spark's `CAST` operation which converts `NaN` to `0` during DOUBLE-to-INT casting. Theoretically, while Apache Spark casts the given value to the given column type first, `NaN` becomes `0`.
   ```scala
   scala> Seq(Double.NaN, 0.0).toDF.selectExpr("cast(value as int)").show
   +-----+
   |value|
   +-----+
   |    0|
   |    0|
   +-----+
   ```
   So, it's a natural behavior in that sequence. However, I agree that `na` function specially needs this fix.
   
   Hi, @gatorsmile and @cloud-fan . How do you think about this PR?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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