[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r361891660 ## File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala ## @@ -456,7 +456,7 @@ 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)) + Seq(Literal(source), buildExpr(target)) Review comment: The new behavior makes more sense, but I agree that the PR description needs update to reflect all the changes. cc @johnhany97 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r353164427 ## File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala ## @@ -404,4 +412,48 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession { df.na.drop("any"), Row("5", "6", "6") :: Nil) } + + test("replace nan with float") { +checkAnswer( + createNaNDF().na.replace("*", Map( +Float.NaN -> 10f + )), + Row(1, new java.lang.Long(1), new java.lang.Short("1"), +new java.lang.Byte("1"), new java.lang.Float(1.0), 1.0) :: + Row(0, new java.lang.Long(0), new java.lang.Short("0"), +new java.lang.Byte("0"), new java.lang.Float(10), new java.lang.Double(10)) :: Nil) + } + + test("replace nan with double") { +checkAnswer( + createNaNDF().na.replace("*", Map( +Double.NaN -> 10.toDouble + )), + Row(1, new java.lang.Long(1), new java.lang.Short("1"), Review comment: ditto 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r353164364 ## File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala ## @@ -404,4 +412,48 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession { df.na.drop("any"), Row("5", "6", "6") :: Nil) } + + test("replace nan with float") { +checkAnswer( + createNaNDF().na.replace("*", Map( +Float.NaN -> 10f + )), + Row(1, new java.lang.Long(1), new java.lang.Short("1"), Review comment: nit: can we use `1L`, `1.toShort`, etc. here too? 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r353132269 ## File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala ## @@ -37,6 +37,16 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession { ).toDF("name", "age", "height") } + def createNaNDF(): DataFrame = { +Seq[(java.lang.Integer, java.lang.Long, java.lang.Short, + java.lang.Byte, java.lang.Float, java.lang.Double)]( Review comment: OK we can keep the type declaration, but can we use `1L`, `1.toShort`, etc. when writing the values? 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r353117839 ## File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala ## @@ -37,6 +37,16 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession { ).toDF("name", "age", "height") } + def createNaNDF(): DataFrame = { +Seq[(java.lang.Integer, java.lang.Long, java.lang.Short, + java.lang.Byte, java.lang.Float, java.lang.Double)]( Review comment: Do we have to use boxed type? how about ``` Seq((1, 1L, 1.toShort, 1.toByte, 1.0f, 1.0), (0, 0L, ...)).toDF... ``` 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r353117371 ## File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala ## @@ -455,8 +455,8 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) { private def replaceCol(col: StructField, replacementMap: Map[_, _]): Column = { 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)) +val branches = replacementMap.flatMap { case (src, target) => +Seq(Literal(src), buildExpr(target)) Review comment: nit: the previous 2 space indentation is corrected. 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs
cloud-fan 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_r353008601 ## 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: checked with scala ``` scala> Float.NaN == 0 res0: Boolean = false scala> Float.NaN.toInt == 0 res1: Boolean = true ``` This is also true in Spark. When comparing float and int, we cast int to float to compare, so `NaN != 0`. I think it's a bug that we cast the value to the column type and compare. We shouldn't do any cast and let the type coercion rules to do proper cast for `CaseKeyWhen` 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org