HyukjinKwon commented on a change in pull request #27278: [SPARK-30569][SQL][PYSPARK][SPARKR] Add percentile_approx DSL functions. URL: https://github.com/apache/spark/pull/27278#discussion_r368777808
########## File path: python/pyspark/sql/functions.py ########## @@ -582,6 +582,44 @@ def nanvl(col1, col2): return Column(sc._jvm.functions.nanvl(_to_java_column(col1), _to_java_column(col2))) +@since(3.0) +def percentile_approx(col, percentage, accuracy=10000): + """Returns the approximate percentile value of numeric column col at the given percentage. + The value of percentage must be between 0.0 and 1.0. + + The accuracy parameter (default: 10000) + is a positive numeric literal which controls approximation accuracy at the cost of memory. + Higher value of accuracy yields better accuracy, 1.0/accuracy is the relative error + of the approximation. + + When percentage is an array, each value of the percentage array must be between 0.0 and 1.0. + In this case, returns the approximate percentile array of column col + at the given percentage array. + + >>> df = (spark.range(0, 1000, 1, 1) + ... .withColumn("id", col("id") % 3) + ... .withColumn("value", randn(42) + col("id") * 10)) Review comment: I know line breaking with `\\` isn't a very good idea in general but that's what the currently codes do. I would rather like to just follow for now. Or, I would just try to don't use multilines. e.g.: ```python df = spark.range(1000).selectExpr("randn(42) AS value") percentage = [0.25, 0.5, 0.75] df.select(percentile_approx("value", percentage).alias("quantiles"))).printSchema() ``` ---------------------------------------------------------------- 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