From c7b7e1d8b17bdf3060c32ac0985e15d923f9680c Mon Sep 17 00:00:00 2001 From: Yuto Akutsu Date: Fri, 3 Sep 2021 13:40:39 +0900 Subject: [PATCH 1/7] add cotangent support on DataFrame --- .../scala/org/apache/spark/sql/functions.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala index c7be437b8c087..306a97b73ab29 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala @@ -1800,6 +1800,24 @@ object functions { */ def cosh(columnName: String): Column = cosh(Column(columnName)) + /** + * @param e angle in radians + * @return cotangent of the angle + * + * @group math_funcs + * @since 3.2.0 + */ + def cot(e: Column): Column = withExpr { Cot(e.expr) } + + /** + * @param columnName angle in radians + * @return cotangent of the angle + * + * @group math_funcs + * @since 3.2.0 + */ + def cot(columnName: String): Column = cot(Column(columnName)) + /** * Computes the exponential of the given value. * From ee170d6162125c566fca88b9628aab681378ed17 Mon Sep 17 00:00:00 2001 From: Yuto Akutsu Date: Fri, 3 Sep 2021 14:57:36 +0900 Subject: [PATCH 2/7] add cotangent support on PySpark --- python/pyspark/sql/functions.py | 17 +++++++++++++++++ python/pyspark/sql/functions.pyi | 1 + 2 files changed, 18 insertions(+) diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py index 6452442097724..194b904a3c5e4 100644 --- a/python/pyspark/sql/functions.py +++ b/python/pyspark/sql/functions.py @@ -377,6 +377,23 @@ def cosh(col): return _invoke_function_over_column("cosh", col) +def cot(col): + """ + .. versionadded:: 3.2.0 + + Parameters + ---------- + col : :class:`~pyspark.sql.Column` or str + angle in radians + + Returns + ------- + :class:`~pyspark.sql.Column` + cotangent of the angle. + """ + return _invoke_function_over_column("cot", col) + + @since(1.4) def exp(col): """ diff --git a/python/pyspark/sql/functions.pyi b/python/pyspark/sql/functions.pyi index 5c39706176a9e..143fa133f4fe0 100644 --- a/python/pyspark/sql/functions.pyi +++ b/python/pyspark/sql/functions.pyi @@ -298,6 +298,7 @@ def collect_set(col: ColumnOrName) -> Column: ... def column(col: str) -> Column: ... def cos(col: ColumnOrName) -> Column: ... def cosh(col: ColumnOrName) -> Column: ... +def cot(col: ColumnOrName) -> Column: ... def count(col: ColumnOrName) -> Column: ... def cume_dist() -> Column: ... def degrees(col: ColumnOrName) -> Column: ... From c1425274409ff209377298b728f4ddec5b35ca1a Mon Sep 17 00:00:00 2001 From: Yuto Akutsu <87687356+yutoacts@users.noreply.github.com> Date: Fri, 3 Sep 2021 17:15:17 +0900 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Hyukjin Kwon --- python/pyspark/sql/functions.py | 6 +++--- .../src/main/scala/org/apache/spark/sql/functions.scala | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py index 194b904a3c5e4..e418c0d11f8f8 100644 --- a/python/pyspark/sql/functions.py +++ b/python/pyspark/sql/functions.py @@ -379,17 +379,17 @@ def cosh(col): def cot(col): """ - .. versionadded:: 3.2.0 + .. versionadded:: 3.3.0 Parameters ---------- col : :class:`~pyspark.sql.Column` or str - angle in radians + Angle in radians Returns ------- :class:`~pyspark.sql.Column` - cotangent of the angle. + Cotangent of the angle. """ return _invoke_function_over_column("cot", col) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala index 306a97b73ab29..f92bbaf21be4b 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala @@ -1805,7 +1805,7 @@ object functions { * @return cotangent of the angle * * @group math_funcs - * @since 3.2.0 + * @since 3.3.0 */ def cot(e: Column): Column = withExpr { Cot(e.expr) } From a4ec1e1f6f605f19ec3740faf0d6678bfc7b17d9 Mon Sep 17 00:00:00 2001 From: Yuto Akutsu Date: Mon, 6 Sep 2021 10:34:16 +0900 Subject: [PATCH 4/7] removed cot function with string parameter --- .../src/main/scala/org/apache/spark/sql/functions.scala | 9 --------- 1 file changed, 9 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala index f92bbaf21be4b..781a2dd5649ed 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala @@ -1809,15 +1809,6 @@ object functions { */ def cot(e: Column): Column = withExpr { Cot(e.expr) } - /** - * @param columnName angle in radians - * @return cotangent of the angle - * - * @group math_funcs - * @since 3.2.0 - */ - def cot(columnName: String): Column = cot(Column(columnName)) - /** * Computes the exponential of the given value. * From d0d65fc7c8825761a386645def1758949144d151 Mon Sep 17 00:00:00 2001 From: Yuto Akutsu Date: Tue, 7 Sep 2021 17:20:06 +0900 Subject: [PATCH 5/7] add cot as a R function --- R/pkg/NAMESPACE | 1 + R/pkg/R/functions.R | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/R/pkg/NAMESPACE b/R/pkg/NAMESPACE index 1f0b69db65151..7fa80853fd23a 100644 --- a/R/pkg/NAMESPACE +++ b/R/pkg/NAMESPACE @@ -259,6 +259,7 @@ exportMethods("%<=>%", "conv", "cos", "cosh", + "cot", "count", "count_distinct", "countDistinct", diff --git a/R/pkg/R/functions.R b/R/pkg/R/functions.R index 40642f19acc12..62066da10d0d8 100644 --- a/R/pkg/R/functions.R +++ b/R/pkg/R/functions.R @@ -870,6 +870,19 @@ setMethod("cosh", column(jc) }) +#' @details +#' \code{cot}: Returns the cotangent of the given value. +#' +#' @rdname column_math_functions +#' @aliases cot cot,Column-method +#' @note cot since 3.3.0 +setMethod("cot", + signature(x = "Column"), + function(x) { + jc <- callJStatic("org.apache.spark.sql.functions", "cot", x@jc) + column(jc) + }) + #' Returns the number of items in a group #' #' This can be used as a column aggregate function with \code{Column} as input, From 61f58d262d5544ee97754a3f2362edc20721134f Mon Sep 17 00:00:00 2001 From: Yuto Akutsu Date: Tue, 7 Sep 2021 17:59:52 +0900 Subject: [PATCH 6/7] trigger AppVeyor From d13384aa35cc1d644f969bb2c9815565651ff215 Mon Sep 17 00:00:00 2001 From: Yuto Akutsu Date: Wed, 8 Sep 2021 11:41:12 +0900 Subject: [PATCH 7/7] added to generic.R and unit-test in test_sparkSQL.R --- R/pkg/R/generics.R | 4 ++++ R/pkg/tests/fulltests/test_sparkSQL.R | 1 + 2 files changed, 5 insertions(+) diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R index 38ad5f742ca68..9ebea3f55e695 100644 --- a/R/pkg/R/generics.R +++ b/R/pkg/R/generics.R @@ -927,6 +927,10 @@ setGeneric("concat_ws", function(sep, x, ...) { standardGeneric("concat_ws") }) #' @name NULL setGeneric("conv", function(x, fromBase, toBase) { standardGeneric("conv") }) +#' @rdname column_math_functions +#' @name NULL +setGeneric("cot", function(x) { standardGeneric("cot") }) + #' @rdname column_aggregate_functions #' @name NULL setGeneric("count_distinct", function(x, ...) { standardGeneric("count_distinct") }) diff --git a/R/pkg/tests/fulltests/test_sparkSQL.R b/R/pkg/tests/fulltests/test_sparkSQL.R index c10f6eddc389c..b97c500749931 100644 --- a/R/pkg/tests/fulltests/test_sparkSQL.R +++ b/R/pkg/tests/fulltests/test_sparkSQL.R @@ -1435,6 +1435,7 @@ test_that("column functions", { desc_nulls_first(c1) + desc_nulls_last(c1) c29 <- acosh(c1) + asinh(c1) + atanh(c1) c30 <- product(c1) + product(c1 * 0.5) + c31 <- cot(c1) # Test if base::is.nan() is exposed expect_equal(is.nan(c("a", "b")), c(FALSE, FALSE))