Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/16776#discussion_r101155454
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/DataFrameStatFunctions.scala ---
@@ -63,44 +63,49 @@ final class DataFrameStatFunctions private[sql](df:
DataFrame) {
* Note that values greater than 1 are accepted but give the same
result as 1.
* @return the approximate quantiles at the given probabilities
*
- * @note NaN values will be removed from the numerical column before
calculation
+ * @note null and NaN values will be removed from the numerical column
before calculation
*
* @since 2.0.0
*/
def approxQuantile(
col: String,
probabilities: Array[Double],
relativeError: Double): Array[Double] = {
- StatFunctions.multipleApproxQuantiles(df.select(col).na.drop(),
- Seq(col), probabilities, relativeError).head.toArray
+ val res = approxQuantile(Array(col), probabilities, relativeError)
+ if (res != null) {
+ res.head
+ } else {
+ null
+ }
}
/**
* Calculates the approximate quantiles of numerical columns of a
DataFrame.
- * @see [[DataFrameStatsFunctions.approxQuantile(col:Str*
approxQuantile]] for
- * detailed description.
+ * @see `DataFrameStatsFunctions.approxQuantile` for detailed
description.
*
- * Note that rows containing any null or NaN values values will be
removed before
- * calculation.
* @param cols the names of the numerical columns
* @param probabilities a list of quantile probabilities
* Each number must belong to [0, 1].
* For example 0 is the minimum, 0.5 is the median, 1 is the maximum.
- * @param relativeError The relative target precision to achieve (>= 0).
+ * @param relativeError The relative target precision to achieve
(greater or equal to 0).
* If set to zero, the exact quantiles are computed, which could be
very expensive.
* Note that values greater than 1 are accepted but give the same
result as 1.
* @return the approximate quantiles at the given probabilities of each
column
*
- * @note Rows containing any NaN values will be removed before
calculation
+ * @note Rows containing any null or NaN values will be removed before
calculation
*
* @since 2.2.0
*/
def approxQuantile(
cols: Array[String],
probabilities: Array[Double],
relativeError: Double): Array[Array[Double]] = {
- StatFunctions.multipleApproxQuantiles(df.select(cols.map(col):
_*).na.drop(), cols,
- probabilities, relativeError).map(_.toArray).toArray
+ try {
+ StatFunctions.multipleApproxQuantiles(df.select(cols.map(col):
_*).na.drop(), cols,
--- End diff --
You're correct, I missed that!
Ok, so #14858 added the `na` dropping to `approxQuantile`. It wasn't there
in the original impl. It can work on data that has `NaN` in the sense that it
will return `NaN`s as part of the quantiles, in some cases. I'm not sure if
that was the intended behavior in the original impl or not cc @thunterdb.
In that sense it's the same as aggs like `min` or `max` - those don't
exclude `NaN` automatically, it's up to the user to handle them. So it could be
best to just remove the `na` dropping from `approxQuantile` (which would revert
to original impl behavior) and put it in `QuantileDiscretizer` which was the
original need.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]