Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[SPARK-22901][PYTHON][FOLLOWUP] Adds the doc for asNondeterministic f…
…or wrapped UDF function

## What changes were proposed in this pull request?

This PR wraps the `asNondeterministic` attribute in the wrapped UDF function to set the docstring properly.

```python
from pyspark.sql.functions import udf
help(udf(lambda x: x).asNondeterministic)
```

Before:

```
Help on function <lambda> in module pyspark.sql.udf:

<lambda> lambda
(END
```

After:

```
Help on function asNondeterministic in module pyspark.sql.udf:

asNondeterministic()
    Updates UserDefinedFunction to nondeterministic.

    .. versionadded:: 2.3
(END)
```

## How was this patch tested?

Manually tested and a simple test was added.

Author: hyukjinkwon <gurwls223@gmail.com>

Closes #20173 from HyukjinKwon/SPARK-22901-followup.
  • Loading branch information
HyukjinKwon authored and gatorsmile committed Jan 6, 2018
1 parent 0377755 commit b66700a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/pyspark/sql/tests.py
Expand Up @@ -413,6 +413,7 @@ def test_nondeterministic_udf2(self):
pydoc.render_doc(udf(lambda: random.randint(6, 6), IntegerType()))
pydoc.render_doc(random_udf)
pydoc.render_doc(random_udf1)
pydoc.render_doc(udf(lambda x: x).asNondeterministic)

def test_nondeterministic_udf_in_aggregate(self):
from pyspark.sql.functions import udf, sum
Expand Down
4 changes: 2 additions & 2 deletions python/pyspark/sql/udf.py
Expand Up @@ -169,8 +169,8 @@ def wrapper(*args):
wrapper.returnType = self.returnType
wrapper.evalType = self.evalType
wrapper.deterministic = self.deterministic
wrapper.asNondeterministic = lambda: self.asNondeterministic()._wrapped()

wrapper.asNondeterministic = functools.wraps(
self.asNondeterministic)(lambda: self.asNondeterministic()._wrapped())
return wrapper

def asNondeterministic(self):
Expand Down

0 comments on commit b66700a

Please sign in to comment.