You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by th...@apache.org on 2023/04/26 15:03:08 UTC

[arrow] branch main updated: GH-35180: [R] Implement bindings for cumsum function (#35339)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new f6bda06f5c GH-35180: [R] Implement bindings for cumsum function (#35339)
f6bda06f5c is described below

commit f6bda06f5cf22879060de23021fe05ae2cfb6d9f
Author: Arnaud Feldmann <60...@users.noreply.github.com>
AuthorDate: Wed Apr 26 17:02:54 2023 +0200

    GH-35180: [R] Implement bindings for cumsum function (#35339)
    
    Fixes #35180
    Can't do the binding to dplyr, as dplyr takes Scalar Expressions and cumsum ( #12460 ) isn't a scalar expression.
    * Closes: #35180
    
    Lead-authored-by: arnaud-feldmann <ar...@gmail.com>
    Co-authored-by: Nic Crane <th...@gmail.com>
    Signed-off-by: Nic Crane <th...@gmail.com>
---
 r/R/arrow-datum.R                     |  2 +-
 r/tests/testthat/test-compute-arith.R | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/r/R/arrow-datum.R b/r/R/arrow-datum.R
index bfebf998a1..4770b03b9c 100644
--- a/r/R/arrow-datum.R
+++ b/r/R/arrow-datum.R
@@ -151,7 +151,7 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) {
     gamma = ,
     digamma = ,
     trigamma = ,
-    cumsum = ,
+    cumsum = eval_array_expression("cumulative_sum_checked", x),
     cumprod = ,
     cummax = ,
     cummin = ,
diff --git a/r/tests/testthat/test-compute-arith.R b/r/tests/testthat/test-compute-arith.R
index 1f3432363f..5cffafe41e 100644
--- a/r/tests/testthat/test-compute-arith.R
+++ b/r/tests/testthat/test-compute-arith.R
@@ -175,9 +175,19 @@ test_that("Math group generics work on Array objects", {
     round(exp(Array$create(c(2L, 1L))), digits = 10),
     Array$create(round(exp(c(2L, 1L)), 10))
   )
+  expect_as_vector(
+    cumsum(Array$create(c(2.3, -1.0, 7.9, NA_real_, 1.0))),
+    c(2.3, 1.3, 9.2, NA_real_, NA_real_)
+  )
+  expect_equal(cumsum(Array$create(-10L)), Array$create(-10L))
+  expect_equal(cumsum(Array$create(NA_integer_)), Array$create(NA_integer_))
+  expect_as_vector(
+    cumsum(ChunkedArray$create(c(2L, 7L, 8L), c(-1L, 2L, 17L, NA_integer_, 3L), 18L)),
+    c(2L, 9L, 17L, 16L, 18L, 35L, NA_integer_, NA_integer_, NA_integer_)
+  )
 
   expect_error(
-    cumsum(Array$create(c(4L, 1L))),
+    cumprod(Array$create(c(4L, 1L))),
     "Unsupported operation on `Array`"
   )
 })