Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19630#discussion_r150571488
--- Diff: python/pyspark/sql/functions.py ---
@@ -2279,7 +2172,38 @@ def pandas_udf(f=None, returnType=StringType()):
.. note:: The user-defined function must be deterministic.
"""
- return _create_udf(f, returnType=returnType,
pythonUdfType=PythonUdfType.PANDAS_UDF)
+ # decorator @pandas_udf(dataType(), functionType)
+ if f is None or isinstance(f, (str, DataType)):
+ # If DataType has been passed as a positional argument
+ # for decorator use it as a returnType
+
+ return_type = f or returnType
+
+ if return_type is None:
+ raise ValueError("Must specify return type.")
+
+ if functionType is not None:
+ # @pandas_udf(dataType, functionType=functionType)
+ # @pandas_udf(returnType=dataType, functionType=functionType)
+ eval_type = functionType.value
+ elif returnType is not None and isinstance(returnType,
PandasUDFType):
+ # @pandas_udf(dataType, functionType)
+ eval_type = returnType.value
+ else:
+ # @pandas_udf(dataType) or @pandas_udf(returnType=dataType)
--- End diff --
how about `@pandas_udf(functionType)`? do we throw exception?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]