You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/04/02 18:09:10 UTC

[GitHub] [arrow] nealrichardson commented on a change in pull request #9875: ARROW-11338: [R] Bindings for quantile and median [WIP]

nealrichardson commented on a change in pull request #9875:
URL: https://github.com/apache/arrow/pull/9875#discussion_r606352305



##########
File path: r/NAMESPACE
##########
@@ -308,6 +311,8 @@ importFrom(rlang,seq2)
 importFrom(rlang,set_names)
 importFrom(rlang,syms)
 importFrom(rlang,warn)
+importFrom(stats,median)
+importFrom(stats,quantile)

Review comment:
       Does this require that we add `stats` to `Imports:` in DESCRIPTION? 

##########
File path: r/R/compute.R
##########
@@ -80,6 +80,36 @@ collect_arrays_from_dots <- function(dots) {
   ChunkedArray$create(!!!arrays)
 }
 
+#' @export
+quantile.ArrowDatum <- function(x,
+                                probs = seq(0, 1, 0.25),
+                                na.rm = FALSE,
+                                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 && TRUE %in% as.vector(unique(is.na(x)))) {
+    stop("Missing values not allowed if 'na.rm' is FALSE", call. = FALSE)

Review comment:
       Why doesn't this just return an Array of NA, like `median` does?
   
   Is this a missing feature on the C++ side (needing a JIRA)? 

##########
File path: r/R/compute.R
##########
@@ -80,6 +80,36 @@ collect_arrays_from_dots <- function(dots) {
   ChunkedArray$create(!!!arrays)
 }
 
+#' @export
+quantile.ArrowDatum <- function(x,
+                                probs = seq(0, 1, 0.25),
+                                na.rm = FALSE,
+                                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 && TRUE %in% as.vector(unique(is.na(x)))) {

Review comment:
       Compare to `scalar_aggregate()` above in this file:
   
   ```suggestion
     if (!na.rm && x$null_count > 0) {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org