Github user icexelloss commented on a diff in the pull request:
https://github.com/apache/spark/pull/19872#discussion_r161658799
--- Diff: python/pyspark/sql/functions.py ---
@@ -2214,6 +2216,37 @@ def pandas_udf(f=None, returnType=None,
functionType=None):
.. seealso:: :meth:`pyspark.sql.GroupedData.apply`
+ 3. GROUP_AGG
+
+ A group aggregate UDF defines a transformation: One or more
`pandas.Series` -> A scalar
+ The returnType should be a primitive data type, e.g, `DoubleType()`.
+ The returned scalar can be either a python primitive type, e.g.,
`int` or `float`
+ or a numpy data type, e.g., `numpy.int64` or `numpy.float64`.
+
+ StructType and ArrayType are currently not supported.
+
+ Group aggregate UDFs are used with
:meth:`pyspark.sql.GroupedData.agg`
+
+ >>> from pyspark.sql.functions import pandas_udf, PandasUDFType
+ >>> df = spark.createDataFrame(
+ ... [(1, 1.0), (1, 2.0), (2, 3.0), (2, 5.0), (2, 10.0)],
+ ... ("id", "v"))
+ >>> @pandas_udf("double", PandasUDFType.GROUP_AGG)
+ ... def mean_udf(v):
--- End diff --
Sorry @cloud-fan, I don't understand this comment, could you elaborate?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]