You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "LuciferYang (via GitHub)" <gi...@apache.org> on 2023/12/31 14:59:06 UTC
[PR] [SPARK-46551][PYTHON][DOCS] Refine docstring of `flatten/sequence/shuffle` [spark]
LuciferYang opened a new pull request, #44548:
URL: https://github.com/apache/spark/pull/44548
### What changes were proposed in this pull request?
This pr refine docstring of `flatten/sequence/shuffle` 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46551][PYTHON][DOCS] Refine docstring of `flatten/sequence/shuffle` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #44548:
URL: https://github.com/apache/spark/pull/44548#issuecomment-1873569870
Merged into master. Thanks @HyukjinKwon @itholic
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46551][PYTHON][DOCS] Refine docstring of `flatten/sequence/shuffle` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang closed pull request #44548: [SPARK-46551][PYTHON][DOCS] Refine docstring of `flatten/sequence/shuffle`
URL: https://github.com/apache/spark/pull/44548
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46551][PYTHON][DOCS] Refine docstring of `flatten/sequence/shuffle` [spark]
Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44548:
URL: https://github.com/apache/spark/pull/44548#discussion_r1439116514
##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -15224,32 +15224,73 @@ def array_sort(
@_try_remote_functions
def shuffle(col: "ColumnOrName") -> Column:
"""
- Collection function: Generates a random permutation of the given array.
+ Array function: Generates a random permutation of the given array.
.. versionadded:: 2.4.0
.. versionchanged:: 3.4.0
Supports Spark Connect.
- Notes
- -----
- The function is non-deterministic.
-
Parameters
----------
col : :class:`~pyspark.sql.Column` or str
- name of column or expression
+ The name of the column or expression to be shuffled.
Returns
-------
:class:`~pyspark.sql.Column`
- an array of elements in random order.
+ A new column that contains an array of elements in random order.
+
+ Notes
+ -----
+ The `shuffle` function is non-deterministic, meaning the order of the output array
+ can be different for each execution.
Examples
--------
- >>> df = spark.createDataFrame([([1, 20, 3, 5],), ([1, 20, None, 3],)], ['data'])
- >>> df.select(shuffle(df.data).alias('s')).collect() # doctest: +SKIP
- [Row(s=[3, 1, 5, 20]), Row(s=[20, None, 3, 1])]
+ Example 1: Shuffling a simple array
+
+ >>> import pyspark.sql.functions as sf
+ >>> df = spark.createDataFrame([([1, 20, 3, 5],)], ['data'])
+ >>> df.select(sf.shuffle(df.data)).show() # doctest: +SKIP
Review Comment:
Sounds reasonable to me
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46551][PYTHON][DOCS] Refine docstring of `flatten/sequence/shuffle` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #44548:
URL: https://github.com/apache/spark/pull/44548#discussion_r1438895953
##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -15224,32 +15224,73 @@ def array_sort(
@_try_remote_functions
def shuffle(col: "ColumnOrName") -> Column:
"""
- Collection function: Generates a random permutation of the given array.
+ Array function: Generates a random permutation of the given array.
.. versionadded:: 2.4.0
.. versionchanged:: 3.4.0
Supports Spark Connect.
- Notes
- -----
- The function is non-deterministic.
-
Parameters
----------
col : :class:`~pyspark.sql.Column` or str
- name of column or expression
+ The name of the column or expression to be shuffled.
Returns
-------
:class:`~pyspark.sql.Column`
- an array of elements in random order.
+ A new column that contains an array of elements in random order.
+
+ Notes
+ -----
+ The `shuffle` function is non-deterministic, meaning the order of the output array
+ can be different for each execution.
Examples
--------
- >>> df = spark.createDataFrame([([1, 20, 3, 5],), ([1, 20, None, 3],)], ['data'])
- >>> df.select(shuffle(df.data).alias('s')).collect() # doctest: +SKIP
- [Row(s=[3, 1, 5, 20]), Row(s=[20, None, 3, 1])]
+ Example 1: Shuffling a simple array
+
+ >>> import pyspark.sql.functions as sf
+ >>> df = spark.createDataFrame([([1, 20, 3, 5],)], ['data'])
+ >>> df.select(sf.shuffle(df.data)).show() # doctest: +SKIP
Review Comment:
Because the execution result of `shuffle` is non-deterministic, only examples are shown here without actual testing. Also, I personally think that the result of `shuffle` should not be sorted again. If there are any other opinions, please let me know.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org