zhengruifeng commented on PR #36181:
URL: https://github.com/apache/spark/pull/36181#issuecomment-1100033744
@xinrong-databricks I guess the reason is that `NA`s in pandas-on-spark
side will be implicitly converted to `null`s in the `internal.spark_frame`
(correct me if i am wrong) , and the statisticl functions always ignore `null`s.
If we can convert `NA`s to `Double.NaN`s instead of `null`s, then the
results should be `NaN`. But I am not sure whether it is safe to use this
attribute.
```
scala> val df = Seq(("1", 1.0), ("2", 2.0), ("3", 3.0), (null,
Double.NaN)).toDF("a", "b").select(col("a").cast("double").as("a"), col("b"))
df: org.apache.spark.sql.DataFrame = [a: double, b: double]
scala> df.show
+----+---+
| a| b|
+----+---+
| 1.0|1.0|
| 2.0|2.0|
| 3.0|3.0|
|null|NaN|
+----+---+
scala> df.select(avg("a"), avg("b")).show
+------+------+
|avg(a)|avg(b)|
+------+------+
| 2.0| NaN|
+------+------+
scala> df.select(sum("a"), sum("b")).show
+------+------+
|sum(a)|sum(b)|
+------+------+
| 6.0| NaN|
+------+------+
scala> df.select(skewness("a"), skewness("b")).show
+-----------+-----------+
|skewness(a)|skewness(b)|
+-----------+-----------+
| 0.0| NaN|
+-----------+-----------+
```
--
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]