From 509825a9548ae371f01ec12b2a2ceef6995d627e Mon Sep 17 00:00:00 2001 From: Patrick Aboyoun Date: Fri, 5 Jul 2024 16:06:47 -0700 Subject: [PATCH 1/2] In Math.ArrowDatum, add support for log2, log1p, cumprod, cummin, cummax and fix bindings after support was added for cumsum --- r/DESCRIPTION | 2 +- r/R/arrow-datum.R | 31 +++++++-------- r/tests/testthat/test-compute-arith.R | 57 +++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 20 deletions(-) diff --git a/r/DESCRIPTION b/r/DESCRIPTION index bb4470e2903..92864cdfbc2 100644 --- a/r/DESCRIPTION +++ b/r/DESCRIPTION @@ -1,6 +1,6 @@ Package: arrow Title: Integration to 'Apache' 'Arrow' -Version: 16.1.0.9000 +Version: 16.1.0.9001 Authors@R: c( person("Neal", "Richardson", email = "neal.p.richardson@gmail.com", role = c("aut")), person("Ian", "Cook", email = "ianmcook@gmail.com", role = c("aut")), diff --git a/r/R/arrow-datum.R b/r/R/arrow-datum.R index 4770b03b9ca..ba513ef470c 100644 --- a/r/R/arrow-datum.R +++ b/r/R/arrow-datum.R @@ -115,19 +115,19 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) { switch(.Generic, abs = eval_array_expression("abs_checked", x), ceiling = eval_array_expression("ceil", x), - sign = , - floor = , - trunc = , - acos = , - asin = , - atan = , - cos = , - sin = , - tan = { - eval_array_expression(.Generic, x) - }, + sign = eval_array_expression("sign", x), + floor = eval_array_expression("floor", x), + trunc = eval_array_expression("trunc", x), + acos = eval_array_expression("acos_checked", x), + asin = eval_array_expression("asin_checked", x), + atan = eval_array_expression("atan", x), + cos = eval_array_expression("cos_checked", x), + sin = eval_array_expression("sin_checked", x), + tan = eval_array_expression("tan_checked", x), log = eval_array_expression("logb_checked", x, base), log10 = eval_array_expression("log10_checked", x), + log2 = eval_array_expression("log2_checked", x), + log1p = eval_array_expression("log1p_checked", x), round = eval_array_expression( "round", x, @@ -135,9 +135,12 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) { ), sqrt = eval_array_expression("sqrt_checked", x), exp = eval_array_expression("power_checked", exp(1), x), + cumsum = eval_array_expression("cumulative_sum_checked", x), + cumprod = eval_array_expression("cumulative_prod_checked", x), + cummax = eval_array_expression("cumulative_max", x), + cummin = eval_array_expression("cumulative_min", x), signif = , expm1 = , - log1p = , cospi = , sinpi = , tanpi = , @@ -151,10 +154,6 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) { gamma = , digamma = , trigamma = , - cumsum = eval_array_expression("cumulative_sum_checked", x), - cumprod = , - cummax = , - cummin = , stop(paste0("Unsupported operation on `", class(x)[1L], "` : "), .Generic, call. = FALSE) ) } diff --git a/r/tests/testthat/test-compute-arith.R b/r/tests/testthat/test-compute-arith.R index 5cffafe41e6..bbdcb10a6b1 100644 --- a/r/tests/testthat/test-compute-arith.R +++ b/r/tests/testthat/test-compute-arith.R @@ -162,6 +162,8 @@ test_that("Math group generics work on Array objects", { Array$create(log(c(0.6, 2.1), base = 2)) ) expect_equal(log10(Array$create(c(0.6, 2.1))), Array$create(log10(c(0.6, 2.1)))) + expect_equal(log2(Array$create(c(0.6, 2.1))), Array$create(log2(c(0.6, 2.1)))) + expect_equal(log1p(Array$create(c(0.6, 2.1, 0))), Array$create(log1p(c(0.6, 2.1, 0)))) expect_equal(round(Array$create(c(0.6, 2.1))), Array$create(c(1, 2))) expect_equal( @@ -175,6 +177,7 @@ 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_) @@ -186,8 +189,56 @@ test_that("Math group generics work on Array objects", { c(2L, 9L, 17L, 16L, 18L, 35L, NA_integer_, NA_integer_, NA_integer_) ) - expect_error( - cumprod(Array$create(c(4L, 1L))), - "Unsupported operation on `Array`" + expect_as_vector( + cumprod(Array$create(c(2.3, -1.0, 7.9, NA_real_, 1.0))), + c(2.3, -2.3, -18.17, NA_real_, NA_real_) + ) + expect_equal(cumprod(Array$create(-10L)), Array$create(-10L)) + expect_equal(cumprod(Array$create(NA_integer_)), Array$create(NA_integer_)) + expect_as_vector( + cumprod(ChunkedArray$create(c(2L, 7L, 8L), c(-1L, 2L, 17L, NA_integer_, 3L), 18L)), + c(2L, 14L, 112L, -112L, -224L, -3808L, NA_integer_, NA_integer_, NA_integer_) + ) + + expect_as_vector( + cummax(Array$create(c(2.3, -1.0, 7.9, NA_real_, 1.0))), + c(2.3, 2.3, 7.9, NA_real_, NA_real_) ) + expect_equal(cummax(Array$create(-10L)), Array$create(-10L)) + expect_equal(cummax(Array$create(NA_integer_)), Array$create(NA_integer_)) + expect_as_vector( + cummax(ChunkedArray$create(c(2L, 7L, 8L), c(-1L, 2L, 17L, NA_integer_, 3L), 18L)), + c(2L, 7L, 8L, 8L, 8L, 17L, NA_integer_, NA_integer_, NA_integer_) + ) + + expect_as_vector( + cummin(Array$create(c(2.3, -1.0, 7.9, NA_real_, 1.0))), + c(2.3, -1, -1, NA_real_, NA_real_) + ) + expect_equal(cummin(Array$create(-10L)), Array$create(-10L)) + expect_equal(cummin(Array$create(NA_integer_)), Array$create(NA_integer_)) + expect_as_vector( + cummin(ChunkedArray$create(c(2L, 7L, 8L), c(-1L, 2L, 17L, NA_integer_, 3L), 18L)), + c(2L, 2L, 2L, -1L, -1L, -1L, NA_integer_, NA_integer_, NA_integer_) + ) + + expect_error(signif(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(expm1(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + + expect_error(cospi(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(sinpi(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(tanpi(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + + expect_error(cosh(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(sinh(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(tanh(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + + expect_error(acosh(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(asinh(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(atanh(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + + expect_error(lgamma(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(gamma(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(digamma(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") + expect_error(trigamma(Array$create(c(4L, 1L))), "Unsupported operation on `Array`") }) From 5133229756f767ff6a96f22047c674848ca7ce16 Mon Sep 17 00:00:00 2001 From: Patrick Aboyoun Date: Sat, 6 Jul 2024 09:12:20 -0700 Subject: [PATCH 2/2] Revert package version bump --- r/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/DESCRIPTION b/r/DESCRIPTION index 92864cdfbc2..bb4470e2903 100644 --- a/r/DESCRIPTION +++ b/r/DESCRIPTION @@ -1,6 +1,6 @@ Package: arrow Title: Integration to 'Apache' 'Arrow' -Version: 16.1.0.9001 +Version: 16.1.0.9000 Authors@R: c( person("Neal", "Richardson", email = "neal.p.richardson@gmail.com", role = c("aut")), person("Ian", "Cook", email = "ianmcook@gmail.com", role = c("aut")),