This is an automated email from the ASF dual-hosted git repository.

npr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d1d03f05a ARROW-16871: [R] Implement exp() and sqrt() in Arrow dplyr 
queries (#13517)
7d1d03f05a is described below

commit 7d1d03f05ada61aa11b2ac432faf349eda8f030e
Author: Christopher D. Higgins <[email protected]>
AuthorDate: Tue Jul 5 16:49:14 2022 -0400

    ARROW-16871: [R] Implement exp() and sqrt() in Arrow dplyr queries (#13517)
    
    In response to https://issues.apache.org/jira/browse/ARROW-16871
    - implement `sqrt` and `exp` bindings for `dplyr`
    - change `sqrt` in `arrow-datum.R` to use `sqrt_checked` rather than 
`power_checked`
    -  write tests for `sqrt` and `exp`
    
    Authored-by: Christopher D. Higgins 
<[email protected]>
    Signed-off-by: Neal Richardson <[email protected]>
---
 r/R/arrow-datum.R                        |  2 +-
 r/R/dplyr-funcs-math.R                   | 15 +++++++++++++++
 r/tests/testthat/test-dplyr-funcs-math.R | 22 ++++++++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/r/R/arrow-datum.R b/r/R/arrow-datum.R
index 4ec5f8f9d6..39362628bb 100644
--- a/r/R/arrow-datum.R
+++ b/r/R/arrow-datum.R
@@ -123,7 +123,7 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 
0) {
       x,
       options = list(ndigits = digits, round_mode = RoundMode$HALF_TO_EVEN)
     ),
-    sqrt = eval_array_expression("power_checked", x, 0.5),
+    sqrt = eval_array_expression("sqrt_checked", x),
     exp = eval_array_expression("power_checked", exp(1), x),
     signif = ,
     expm1 = ,
diff --git a/r/R/dplyr-funcs-math.R b/r/R/dplyr-funcs-math.R
index b92c202d04..0ba2ddc856 100644
--- a/r/R/dplyr-funcs-math.R
+++ b/r/R/dplyr-funcs-math.R
@@ -80,4 +80,19 @@ register_bindings_math <- function() {
       options = list(ndigits = digits, round_mode = RoundMode$HALF_TO_EVEN)
     )
   })
+
+  register_binding("sqrt", function(x) {
+    build_expr(
+      "sqrt_checked",
+      x
+    )
+  })
+
+  register_binding("exp", function(x) {
+    build_expr(
+      "power_checked",
+      exp(1),
+      x
+    )
+  })
 }
diff --git a/r/tests/testthat/test-dplyr-funcs-math.R 
b/r/tests/testthat/test-dplyr-funcs-math.R
index dd982c9942..47a9f0b7c0 100644
--- a/r/tests/testthat/test-dplyr-funcs-math.R
+++ b/r/tests/testthat/test-dplyr-funcs-math.R
@@ -330,3 +330,25 @@ test_that("floor division maintains type consistency with 
R", {
     df
   )
 })
+
+test_that("exp()", {
+  df <- tibble(x = c(1:5, NA))
+
+  compare_dplyr_binding(
+    .input %>%
+      mutate(y = exp(x)) %>%
+      collect(),
+    df
+  )
+})
+
+test_that("sqrt()", {
+  df <- tibble(x = c(1:5, NA))
+
+  compare_dplyr_binding(
+    .input %>%
+      mutate(y = sqrt(x)) %>%
+      collect(),
+    df
+  )
+})

Reply via email to