Github user zero323 commented on a diff in the pull request:
https://github.com/apache/spark/pull/16533#discussion_r97954697
--- Diff: python/pyspark/sql/functions.py ---
@@ -1862,9 +1862,33 @@ def udf(f, returnType=StringType()):
>>> slen = udf(lambda s: len(s), IntegerType())
>>> df.select(slen(df.name).alias('slen')).collect()
[Row(slen=5), Row(slen=3)]
+ >>> @udf
+ ... def to_upper(s):
+ ... if s is not None:
+ ... return s.upper()
+ ...
+ >>> @udf(returnType=IntegerType())
+ ... def add_one(x):
+ ... if x is not None:
+ ... return x + 1
+ ...
"""
return UserDefinedFunction(f, returnType)
+
[email protected](_udf)
+def udf(f=None, returnType=StringType()):
--- End diff --
We can, but I am not sure if we should keep the original version or
acknowledge change of behavior and use potential merge version.
Regarding docstring I am a bit reluctant. It can be documented for dev
purposes but any user facing doc will have to expose ugly implementation
details.
def udf(
f: typing.Union[None, typing.Callable, pyspark.sql.types.DataType],
returnType: pyspark.sql.types.DataType=StringType()
) -> Union[types.FunctionType, functools.partial]:
...
Maybe I a wrong but it can bring more confusion than it is worth. We can of
course move `_udf` docstring and skip wrapping (we considered different
implementations where signatures differed) but of course it won't be accurate.
---
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]