Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions python/pyspark/sql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,13 @@ def udf(f=None, returnType=StringType()):
duplicate invocations may be eliminated or the function may even be invoked more times than
it is present in the query.

.. note:: The user-defined functions do not support conditional execution by using them with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, should we maybe clarify the output itself is correct if it does not cause the runtime failure by the condition? Maybe I am too much worried but think it might mislead the output is incorrect at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think this is a valid worry. Thanks.

SQL conditional expressions such as `when` or `if`. The functions still apply on all rows no
matter the conditions are met or not. So the output is correct if the functions can be
correctly run on all rows without failure. If the functions can cause runtime failure on the
rows that do not satisfy the conditions, the suggested workaround is to incorporate the
condition logic into the functions.

:param f: python function if used as a standalone function
:param returnType: a :class:`pyspark.sql.types.DataType` object

Expand Down Expand Up @@ -2278,6 +2285,13 @@ def pandas_udf(f=None, returnType=StringType()):
.. seealso:: :meth:`pyspark.sql.GroupedData.apply`

.. note:: The user-defined function must be deterministic.

.. note:: The user-defined functions do not support conditional execution by using them with
SQL conditional expressions such as `when` or `if`. The functions still apply on all rows no
matter the conditions are met or not. So the output is correct if the functions can be
correctly run on all rows without failure. If the functions can cause runtime failure on the
rows that do not satisfy the conditions, the suggested workaround is to incorporate the
condition logic into the functions.
"""
return _create_udf(f, returnType=returnType, pythonUdfType=PythonUdfType.PANDAS_UDF)

Expand Down