Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions r/R/dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ arrow_mask <- function(.data) {
# Some R functions will still try to evaluate on an Expression
# and return NA with a warning
fail <- function(...) stop("Not implemented")
for (f in c("mean")) {
for (f in c("mean", "sd")) {
f_env[[f]] <- fail
}

Expand Down Expand Up @@ -1006,7 +1006,6 @@ abandon_ship <- function(call, .data, msg = NULL) {
stop(msg, "\nCall collect() first to pull data into R.", call. = FALSE)
}
}

# else, collect and call dplyr method
if (!is.null(msg)) {
warning(msg, "; pulling data into R", immediate. = TRUE, call. = FALSE)
Expand Down
5 changes: 5 additions & 0 deletions r/src/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ std::shared_ptr<arrow::compute::FunctionOptions> make_compute_options(
max_replacements);
}

if (func_name == "variance" || func_name == "stddev") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH this is probably the only code addition we want to keep here.

using Options = arrow::compute::VarianceOptions;
return std::make_shared<Options>(cpp11::as_cpp<int64_t>(options["ddof"]));
}

return nullptr;
}

Expand Down
18 changes: 18 additions & 0 deletions r/tests/testthat/test-compute-aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,21 @@ test_that("all.Array and all.ChunkedArray", {
expect_vector_equal(all(input, na.rm = TRUE), data_logical)

})

test_that("variance", {
data <- c(-37, 267, 88, -120, 9, 101, -65, -23, NA)
arr <- Array$create(data)
chunked_arr <- ChunkedArray$create(data)

expect_equal(call_function("variance", arr, options = list(ddof = 5)), Scalar$create(34596))
expect_equal(call_function("variance", chunked_arr, options = list(ddof = 5)), Scalar$create(34596))
})

test_that("stddev", {
data <- c(-37, 267, 88, -120, 9, 101, -65, -23, NA)
arr <- Array$create(data)
chunked_arr <- ChunkedArray$create(data)

expect_equal(call_function("stddev", arr, options = list(ddof = 5)), Scalar$create(186))
expect_equal(call_function("stddev", chunked_arr, options = list(ddof = 5)), Scalar$create(186))
})