Yikun commented on code in PR #37575:
URL: https://github.com/apache/spark/pull/37575#discussion_r949917079
##########
python/pyspark/sql/functions.py:
##########
@@ -307,34 +485,120 @@ def min_by(col: "ColumnOrName", ord: "ColumnOrName") ->
Column:
return _invoke_function_over_columns("min_by", col, ord)
-@since(1.3)
def count(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the number of items in a group.
+
+ .. versionadded:: 1.3.0
+
+ Parameters
+ ----------
+ col : :class:`~pyspark.sql.Column` or str
+ target column to compute on.
+
+ Returns
+ -------
+ :class:`~pyspark.sql.Column`
+ column for compuated results.
+
+ Examples
+ --------
+ Count by all columns (start), and by a column that does not count ``None``.
+
+ >>> df = spark.createDataFrame([(None,), ("a",), ("b",), ("c",)],
schema=["alphabets"])
+ >>> df.select(count(expr("*")), count(df.alphabets)).show()
+ +--------+----------------+
+ |count(1)|count(alphabets)|
+ +--------+----------------+
+ | 4| 3|
+ +--------+----------------+
"""
return _invoke_function_over_columns("count", col)
-@since(1.3)
def sum(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the sum of all values in the expression.
+
+ .. versionadded:: 1.3.0
+
+ Parameters
+ ----------
+ col : :class:`~pyspark.sql.Column` or str
+ target column to compute on.
+
+ Returns
+ -------
+ :class:`~pyspark.sql.Column`
+ the column for compuated results.
+
+ Examples
+ --------
+ >>> df = spark.range(10)
+ >>> df.select(sum(df["id"])).show()
+ +-------+
+ |sum(id)|
+ +-------+
+ | 45|
+ +-------+
"""
return _invoke_function_over_columns("sum", col)
-@since(1.3)
def avg(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the average of the values in a group.
+
+ .. versionadded:: 1.3.0
+
+ Parameters
+ ----------
+ col : :class:`~pyspark.sql.Column` or str
+ target column to compute on.
+
+ Returns
+ -------
+ :class:`~pyspark.sql.Column`
+ the column for compuated results.
+
+ Examples
+ --------
+ >>> df = spark.range(10)
+ >>> df.select(avg(col("id"))).show()
+ +-------+
+ |avg(id)|
+ +-------+
+ | 4.5|
+ +-------+
"""
return _invoke_function_over_columns("avg", col)
-@since(1.3)
def mean(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the average of the values in a group.
+
+ .. versionadded:: 1.3.0
Review Comment:
https://github.com/apache/spark/blob/f98f9f8566243a8a01edcaad3b847bbd2f52305b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L705-L721
According to above, it should be `1.4.0`?
history commit:
https://github.com/apache/spark/commit/4e6a310f8062102ea6a022fb21171f896c8296ae#diff-af2c27f925c4634d7efc25df50dc66b99e5a79f6f897dc4c49302492a48ca3f6R186
##########
python/pyspark/sql/functions.py:
##########
@@ -307,34 +485,120 @@ def min_by(col: "ColumnOrName", ord: "ColumnOrName") ->
Column:
return _invoke_function_over_columns("min_by", col, ord)
-@since(1.3)
def count(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the number of items in a group.
+
+ .. versionadded:: 1.3.0
+
+ Parameters
+ ----------
+ col : :class:`~pyspark.sql.Column` or str
+ target column to compute on.
+
+ Returns
+ -------
+ :class:`~pyspark.sql.Column`
+ column for compuated results.
+
+ Examples
+ --------
+ Count by all columns (start), and by a column that does not count ``None``.
+
+ >>> df = spark.createDataFrame([(None,), ("a",), ("b",), ("c",)],
schema=["alphabets"])
+ >>> df.select(count(expr("*")), count(df.alphabets)).show()
+ +--------+----------------+
+ |count(1)|count(alphabets)|
+ +--------+----------------+
+ | 4| 3|
+ +--------+----------------+
"""
return _invoke_function_over_columns("count", col)
-@since(1.3)
def sum(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the sum of all values in the expression.
+
+ .. versionadded:: 1.3.0
+
+ Parameters
+ ----------
+ col : :class:`~pyspark.sql.Column` or str
+ target column to compute on.
+
+ Returns
+ -------
+ :class:`~pyspark.sql.Column`
+ the column for compuated results.
+
+ Examples
+ --------
+ >>> df = spark.range(10)
+ >>> df.select(sum(df["id"])).show()
+ +-------+
+ |sum(id)|
+ +-------+
+ | 45|
+ +-------+
"""
return _invoke_function_over_columns("sum", col)
-@since(1.3)
def avg(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the average of the values in a group.
+
+ .. versionadded:: 1.3.0
+
+ Parameters
+ ----------
+ col : :class:`~pyspark.sql.Column` or str
+ target column to compute on.
+
+ Returns
+ -------
+ :class:`~pyspark.sql.Column`
+ the column for compuated results.
+
+ Examples
+ --------
+ >>> df = spark.range(10)
+ >>> df.select(avg(col("id"))).show()
+ +-------+
+ |avg(id)|
+ +-------+
+ | 4.5|
+ +-------+
"""
return _invoke_function_over_columns("avg", col)
-@since(1.3)
def mean(col: "ColumnOrName") -> Column:
"""
Aggregate function: returns the average of the values in a group.
+
Review Comment:
mention to `mean` is alias of `avg`?
##########
python/pyspark/sql/functions.py:
##########
@@ -454,11 +777,26 @@ def asin(col: "ColumnOrName") -> Column:
.. versionadded:: 1.3.0
Review Comment:
https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L1575-L1589
1.4.0
history commits:
https://github.com/apache/spark/commit/4e6a310f8062102ea6a022fb21171f896c8296ae#diff-af2c27f925c4634d7efc25df50dc66b99e5a79f6f897dc4c49302492a48ca3f6R186
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]