This is an automated email from the ASF dual-hosted git repository. dongjoon pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push: new f03f3d01176d [SPARK-46560][PYTHON][DOCS] Refine docstring `reverse/map_contains_key` f03f3d01176d is described below commit f03f3d01176d5c6aae606937e4a4b033ba1c3017 Author: panbingkun <panbing...@baidu.com> AuthorDate: Thu Jan 4 20:10:56 2024 -0800 [SPARK-46560][PYTHON][DOCS] Refine docstring `reverse/map_contains_key` ### What changes were proposed in this pull request? The pr aims to refine docstring of `reverse/map_contains_key`. ### Why are the changes needed? To improve PySpark documentation. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manually test. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #44561 from panbingkun/SPARK-46560. Lead-authored-by: panbingkun <panbing...@baidu.com> Co-authored-by: panbingkun <pbk1...@gmail.com> Signed-off-by: Dongjoon Hyun <dh...@apple.com> --- python/pyspark/sql/functions/builtin.py | 50 ++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/python/pyspark/sql/functions/builtin.py b/python/pyspark/sql/functions/builtin.py index 4147e71f4bb4..50d3b6cc01ce 100644 --- a/python/pyspark/sql/functions/builtin.py +++ b/python/pyspark/sql/functions/builtin.py @@ -15303,7 +15303,7 @@ def shuffle(col: "ColumnOrName") -> Column: @_try_remote_functions def reverse(col: "ColumnOrName") -> Column: """ - Collection function: returns a reversed string or an array with reverse order of elements. + Collection function: returns a reversed string or an array with elements in reverse order. .. versionadded:: 1.5.0 @@ -15313,21 +15313,38 @@ def reverse(col: "ColumnOrName") -> Column: Parameters ---------- col : :class:`~pyspark.sql.Column` or str - name of column or expression + The name of the column or an expression that represents the element to be reversed. Returns ------- :class:`~pyspark.sql.Column` - array of elements in reverse order. + A new column that contains a reversed string or an array with elements in reverse order. Examples -------- + Example 1: Reverse a string + + >>> import pyspark.sql.functions as sf >>> df = spark.createDataFrame([('Spark SQL',)], ['data']) - >>> df.select(reverse(df.data).alias('s')).collect() - [Row(s='LQS krapS')] + >>> df.select(sf.reverse(df.data)).show() + +-------------+ + |reverse(data)| + +-------------+ + | LQS krapS| + +-------------+ + + Example 2: Reverse an array + + >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([([2, 1, 3],) ,([1],) ,([],)], ['data']) - >>> df.select(reverse(df.data).alias('r')).collect() - [Row(r=[3, 1, 2]), Row(r=[1]), Row(r=[])] + >>> df.select(sf.reverse(df.data)).show() + +-------------+ + |reverse(data)| + +-------------+ + | [3, 1, 2]| + | [1]| + | []| + +-------------+ """ return _invoke_function_over_columns("reverse", col) @@ -15406,7 +15423,7 @@ def flatten(col: "ColumnOrName") -> Column: @_try_remote_functions def map_contains_key(col: "ColumnOrName", value: Any) -> Column: """ - Returns true if the map contains the key. + Map function: Returns true if the map contains the key. .. versionadded:: 3.4.0 @@ -15416,9 +15433,9 @@ def map_contains_key(col: "ColumnOrName", value: Any) -> Column: Parameters ---------- col : :class:`~pyspark.sql.Column` or str - name of column or expression + The name of the column or an expression that represents the map. value : - a literal value + A literal value. Returns ------- @@ -15427,15 +15444,22 @@ def map_contains_key(col: "ColumnOrName", value: Any) -> Column: Examples -------- - >>> from pyspark.sql.functions import map_contains_key + Example 1: The key is in the map + + >>> from pyspark.sql import functions as sf >>> df = spark.sql("SELECT map(1, 'a', 2, 'b') as data") - >>> df.select(map_contains_key("data", 1)).show() + >>> df.select(sf.map_contains_key("data", 1)).show() +-------------------------+ |map_contains_key(data, 1)| +-------------------------+ | true| +-------------------------+ - >>> df.select(map_contains_key("data", -1)).show() + + Example 2: The key is not in the map + + >>> from pyspark.sql import functions as sf + >>> df = spark.sql("SELECT map(1, 'a', 2, 'b') as data") + >>> df.select(sf.map_contains_key("data", -1)).show() +--------------------------+ |map_contains_key(data, -1)| +--------------------------+ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org