This is an automated email from the ASF dual-hosted git repository. gurwls223 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 c0f07d3c193 [SPARK-41803][CONNECT][PYTHON] Add missing function `log(arg1, arg2)` c0f07d3c193 is described below commit c0f07d3c193f6df92a736634be65bf42c3c4154c Author: Ruifeng Zheng <ruife...@apache.org> AuthorDate: Tue Jan 3 09:56:49 2023 +0900 [SPARK-41803][CONNECT][PYTHON] Add missing function `log(arg1, arg2)` ### What changes were proposed in this pull request? Add missing function `log(arg1, arg2)` ### Why are the changes needed? for API coverage ### Does this PR introduce _any_ user-facing change? yes ### How was this patch tested? added ut Closes #39339 from zhengruifeng/connect_function_log. Authored-by: Ruifeng Zheng <ruife...@apache.org> Signed-off-by: Hyukjin Kwon <gurwls...@apache.org> --- python/pyspark/sql/connect/functions.py | 10 ++++++++-- python/pyspark/sql/tests/connect/test_connect_function.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/pyspark/sql/connect/functions.py b/python/pyspark/sql/connect/functions.py index 436eb9f7c73..23196e888e3 100644 --- a/python/pyspark/sql/connect/functions.py +++ b/python/pyspark/sql/connect/functions.py @@ -28,6 +28,7 @@ from typing import ( Tuple, Callable, ValuesView, + cast, ) from pyspark.sql.connect.column import Column @@ -548,8 +549,13 @@ def hypot(col1: Union["ColumnOrName", float], col2: Union["ColumnOrName", float] hypot.__doc__ = pysparkfuncs.hypot.__doc__ -def log(col: "ColumnOrName") -> Column: - return _invoke_function_over_columns("ln", col) +def log(arg1: Union["ColumnOrName", float], arg2: Optional["ColumnOrName"] = None) -> Column: + if arg2 is None: + # in this case, arg1 should be "ColumnOrName" + return _invoke_function("ln", _to_col(cast("ColumnOrName", arg1))) + else: + # in this case, arg1 should be a float + return _invoke_function("log", lit(cast(float, arg1)), _to_col(arg2)) log.__doc__ = pysparkfuncs.log.__doc__ diff --git a/python/pyspark/sql/tests/connect/test_connect_function.py b/python/pyspark/sql/tests/connect/test_connect_function.py index 6fea8da14c7..0dda3e99fcf 100644 --- a/python/pyspark/sql/tests/connect/test_connect_function.py +++ b/python/pyspark/sql/tests/connect/test_connect_function.py @@ -448,6 +448,12 @@ class SparkConnectFunctionTests(SparkConnectFuncTestCase): sdf.select(sfunc("b"), sfunc(sdf.c)).toPandas(), ) + # test log(arg1, arg2) + self.assert_eq( + cdf.select(CF.log(1.1, "b"), CF.log(1.2, cdf.c)).toPandas(), + sdf.select(SF.log(1.1, "b"), SF.log(1.2, sdf.c)).toPandas(), + ) + self.assert_eq( cdf.select(CF.atan2("b", cdf.c)).toPandas(), sdf.select(SF.atan2("b", sdf.c)).toPandas(), --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org