Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-11338: [R] Bindings for quantile and median#9875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
93276a0db5250ae5621f6d35902cd60361b79fa50bf60cd0cd697d7c188ceea5b3b43de4759550b27da75dbe77eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,6 +30,7 @@ Imports: | ||
| purrr, | ||
| R6, | ||
| rlang, | ||
| stats, | ||
| tidyselect, | ||
| utils, | ||
| vctrs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -80,6 +80,49 @@ collect_arrays_from_dots <- function(dots) { | ||
| ChunkedArray$create(!!!arrays) | ||
| } | ||
| #' @export | ||
| quantile.ArrowDatum <- function(x, | ||
| probs = seq(0, 1, 0.25), | ||
| na.rm = FALSE, | ||
| type = 7, | ||
| interpolation = c("linear", "lower", "higher", "nearest", "midpoint"), | ||
| ...) { | ||
| if (inherits(x, "Scalar")) x <- Array$create(x) | ||
| assert_is(probs, c("numeric", "integer")) | ||
| assert_that(length(probs) > 0) | ||
| assert_that(all(probs >= 0 & probs <= 1)) | ||
| if (!na.rm && x$null_count > 0) { | ||
| stop("Missing values not allowed if 'na.rm' is FALSE", call. = FALSE) | ||
ianmcook marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| if (type != 7) { | ||
| stop( | ||
| "Argument `type` not supported in Arrow. To control the quantile ", | ||
| "interpolation algorithm, set argument `interpolation` to one of: ", | ||
| "\"linear\" (the default), \"lower\", \"higher\", \"nearest\", or ", | ||
| "\"midpoint\".", | ||
| call. = FALSE | ||
| ) | ||
| } | ||
| interpolation <- QuantileInterpolation[[toupper(match.arg(interpolation))]] | ||
| out <- call_function("quantile", x, options = list(q = probs, interpolation = interpolation)) | ||
| if (length(out) == 0) { | ||
ianmcook marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # When there are no non-missing values in the data, the Arrow quantile | ||
| # function returns an empty Array, but for consistency with the R quantile | ||
| # function, we want an Array of NA_real_ with the same length as probs | ||
| out <- Array$create(rep(NA_real_, length(probs))) | ||
| } | ||
| out | ||
| } | ||
| #' @export | ||
| median.ArrowDatum <- function(x, na.rm = FALSE, ...) { | ||
| if (!na.rm && x$null_count > 0) { | ||
| Scalar$create(NA_real_) | ||
| } else { | ||
| Scalar$create(quantile(x, probs = 0.5, na.rm = TRUE, ...)) | ||
| } | ||
| } | ||
| #' @export | ||
| unique.ArrowDatum <- function(x, incomparables = FALSE, ...) { | ||
| call_function("unique", x) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.