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 5056a17919ac [SPARK-46897][PYTHON][DOCS] Refine docstring of `bit_and/bit_or/bit_xor` 5056a17919ac is described below commit 5056a17919ac88d35475dd13ae4167e783f9504a Author: yangjie01 <yangji...@baidu.com> AuthorDate: Sun Jan 28 21:33:39 2024 -0800 [SPARK-46897][PYTHON][DOCS] Refine docstring of `bit_and/bit_or/bit_xor` ### What changes were proposed in this pull request? This pr refine docstring of `bit_and/bit_or/bit_xor` and add some new examples. ### Why are the changes needed? To improve PySpark documentation ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Pass Github Actions ### Was this patch authored or co-authored using generative AI tooling? No Closes #44923 from LuciferYang/SPARK-46897. Authored-by: yangjie01 <yangji...@baidu.com> Signed-off-by: Dongjoon Hyun <dh...@apple.com> --- python/pyspark/sql/functions/builtin.py | 138 ++++++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 6 deletions(-) diff --git a/python/pyspark/sql/functions/builtin.py b/python/pyspark/sql/functions/builtin.py index d3a94fe4b9e9..0932ac1c2843 100644 --- a/python/pyspark/sql/functions/builtin.py +++ b/python/pyspark/sql/functions/builtin.py @@ -3790,9 +3790,51 @@ def bit_and(col: "ColumnOrName") -> Column: Examples -------- + Example 1: Bitwise AND with all non-null values + + >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([[1],[1],[2]], ["c"]) - >>> df.select(bit_and("c")).first() - Row(bit_and(c)=0) + >>> df.select(sf.bit_and("c")).show() + +----------+ + |bit_and(c)| + +----------+ + | 0| + +----------+ + + Example 2: Bitwise AND with null values + + >>> from pyspark.sql import functions as sf + >>> df = spark.createDataFrame([[1],[None],[2]], ["c"]) + >>> df.select(sf.bit_and("c")).show() + +----------+ + |bit_and(c)| + +----------+ + | 0| + +----------+ + + Example 3: Bitwise AND with all null values + + >>> from pyspark.sql import functions as sf + >>> from pyspark.sql.types import IntegerType, StructType, StructField + >>> schema = StructType([StructField("c", IntegerType(), True)]) + >>> df = spark.createDataFrame([[None],[None],[None]], schema=schema) + >>> df.select(sf.bit_and("c")).show() + +----------+ + |bit_and(c)| + +----------+ + | NULL| + +----------+ + + Example 4: Bitwise AND with single input value + + >>> from pyspark.sql import functions as sf + >>> df = spark.createDataFrame([[5]], ["c"]) + >>> df.select(sf.bit_and("c")).show() + +----------+ + |bit_and(c)| + +----------+ + | 5| + +----------+ """ return _invoke_function_over_columns("bit_and", col) @@ -3816,9 +3858,51 @@ def bit_or(col: "ColumnOrName") -> Column: Examples -------- + Example 1: Bitwise OR with all non-null values + + >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([[1],[1],[2]], ["c"]) - >>> df.select(bit_or("c")).first() - Row(bit_or(c)=3) + >>> df.select(sf.bit_or("c")).show() + +---------+ + |bit_or(c)| + +---------+ + | 3| + +---------+ + + Example 2: Bitwise OR with some null values + + >>> from pyspark.sql import functions as sf + >>> df = spark.createDataFrame([[1],[None],[2]], ["c"]) + >>> df.select(sf.bit_or("c")).show() + +---------+ + |bit_or(c)| + +---------+ + | 3| + +---------+ + + Example 3: Bitwise OR with all null values + + >>> from pyspark.sql import functions as sf + >>> from pyspark.sql.types import IntegerType, StructType, StructField + >>> schema = StructType([StructField("c", IntegerType(), True)]) + >>> df = spark.createDataFrame([[None],[None],[None]], schema=schema) + >>> df.select(sf.bit_or("c")).show() + +---------+ + |bit_or(c)| + +---------+ + | NULL| + +---------+ + + Example 4: Bitwise OR with single input value + + >>> from pyspark.sql import functions as sf + >>> df = spark.createDataFrame([[5]], ["c"]) + >>> df.select(sf.bit_or("c")).show() + +---------+ + |bit_or(c)| + +---------+ + | 5| + +---------+ """ return _invoke_function_over_columns("bit_or", col) @@ -3842,9 +3926,51 @@ def bit_xor(col: "ColumnOrName") -> Column: Examples -------- + Example 1: Bitwise XOR with all non-null values + + >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([[1],[1],[2]], ["c"]) - >>> df.select(bit_xor("c")).first() - Row(bit_xor(c)=2) + >>> df.select(sf.bit_xor("c")).show() + +----------+ + |bit_xor(c)| + +----------+ + | 2| + +----------+ + + Example 2: Bitwise XOR with some null values + + >>> from pyspark.sql import functions as sf + >>> df = spark.createDataFrame([[1],[None],[2]], ["c"]) + >>> df.select(sf.bit_xor("c")).show() + +----------+ + |bit_xor(c)| + +----------+ + | 3| + +----------+ + + Example 3: Bitwise XOR with all null values + + >>> from pyspark.sql import functions as sf + >>> from pyspark.sql.types import IntegerType, StructType, StructField + >>> schema = StructType([StructField("c", IntegerType(), True)]) + >>> df = spark.createDataFrame([[None],[None],[None]], schema=schema) + >>> df.select(sf.bit_xor("c")).show() + +----------+ + |bit_xor(c)| + +----------+ + | NULL| + +----------+ + + Example 4: Bitwise XOR with single input value + + >>> from pyspark.sql import functions as sf + >>> df = spark.createDataFrame([[5]], ["c"]) + >>> df.select(sf.bit_xor("c")).show() + +----------+ + |bit_xor(c)| + +----------+ + | 5| + +----------+ """ return _invoke_function_over_columns("bit_xor", col) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org