rok commented on a change in pull request #9758:
URL: https://github.com/apache/arrow/pull/9758#discussion_r635065386



##########
File path: r/R/compute.R
##########
@@ -110,15 +114,16 @@ max.ArrowDatum <- function(..., na.rm = FALSE) {
   scalar_aggregate("min_max", ..., na.rm = na.rm)$GetFieldByName("max")
 }
 
-scalar_aggregate <- function(FUN, ..., na.rm = FALSE) {
+scalar_aggregate <- function(FUN, ..., na.rm = FALSE, na.min_count = 0) {
   a <- collect_arrays_from_dots(list(...))
-  if (!na.rm && a$null_count > 0 && (FUN %in% c("mean", "sum"))) {
-    # Arrow sum/mean function always drops NAs so handle that here
-    # https://issues.apache.org/jira/browse/ARROW-9054
-    return(Scalar$create(NA_real_))
+  if (FUN %in% c("mean", "sum") && !na.rm) {
+    na.min_count = length(a)

Review comment:
       ```suggestion
     if (FUN %in% c("mean", "sum") && !na.rm) {
       # When not removing null values we expect for all values to be not null 
and 
       # return null otherwise. We do that by setting minimum count of non-null 
       # option values to full array length.
       na.min_count = length(a)
   ```

##########
File path: r/R/compute.R
##########
@@ -110,15 +114,16 @@ max.ArrowDatum <- function(..., na.rm = FALSE) {
   scalar_aggregate("min_max", ..., na.rm = na.rm)$GetFieldByName("max")
 }
 
-scalar_aggregate <- function(FUN, ..., na.rm = FALSE) {
+scalar_aggregate <- function(FUN, ..., na.rm = FALSE, na.min_count = 0) {
   a <- collect_arrays_from_dots(list(...))
-  if (!na.rm && a$null_count > 0 && (FUN %in% c("mean", "sum"))) {
-    # Arrow sum/mean function always drops NAs so handle that here
-    # https://issues.apache.org/jira/browse/ARROW-9054
-    return(Scalar$create(NA_real_))
+  if (FUN %in% c("mean", "sum") && !na.rm) {
+    na.min_count = length(a)
+  }
+  if (FUN == "min_max" && na.rm && a$null_count == length(a)) {
+    Array$create(data.frame(min=Inf, max=-Inf))

Review comment:
       ```suggestion
       Array$create(data.frame(min=Inf, max=-Inf))
       # In case na.rm == true and all values in array are null R will
       # return Inf/-Inf. As we can not express Inf/-Inf for integer and
       # boolean types in C++ we correct for this with a check here.
   ```




-- 
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:
[email protected]


Reply via email to