Skip to content

Commit f6bda06

Browse files
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 <arnaud.feldmann@gmail.com> Co-authored-by: Nic Crane <thisisnic@gmail.com> Signed-off-by: Nic Crane <thisisnic@gmail.com>
1 parent a5ac94e commit f6bda06

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

r/R/arrow-datum.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) {
151151
gamma = ,
152152
digamma = ,
153153
trigamma = ,
154-
cumsum = ,
154+
cumsum = eval_array_expression("cumulative_sum_checked", x),
155155
cumprod = ,
156156
cummax = ,
157157
cummin = ,

r/tests/testthat/test-compute-arith.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,19 @@ test_that("Math group generics work on Array objects", {
175175
round(exp(Array$create(c(2L, 1L))), digits = 10),
176176
Array$create(round(exp(c(2L, 1L)), 10))
177177
)
178+
expect_as_vector(
179+
cumsum(Array$create(c(2.3, -1.0, 7.9, NA_real_, 1.0))),
180+
c(2.3, 1.3, 9.2, NA_real_, NA_real_)
181+
)
182+
expect_equal(cumsum(Array$create(-10L)), Array$create(-10L))
183+
expect_equal(cumsum(Array$create(NA_integer_)), Array$create(NA_integer_))
184+
expect_as_vector(
185+
cumsum(ChunkedArray$create(c(2L, 7L, 8L), c(-1L, 2L, 17L, NA_integer_, 3L), 18L)),
186+
c(2L, 9L, 17L, 16L, 18L, 35L, NA_integer_, NA_integer_, NA_integer_)
187+
)
178188

179189
expect_error(
180-
cumsum(Array$create(c(4L, 1L))),
190+
cumprod(Array$create(c(4L, 1L))),
181191
"Unsupported operation on `Array`"
182192
)
183193
})

0 commit comments

Comments
 (0)