romainfrancois commented on a change in pull request #11225:
URL: https://github.com/apache/arrow/pull/11225#discussion_r718286719



##########
File path: r/src/altrep.cpp
##########
@@ -274,210 +257,342 @@ struct AltrepArrayPrimitive {
 
   // This cannot keep the external pointer to an Arrow object through
   // R serialization, so return the materialized
-  SEXP Serialized_state() {
-    Materialize();
-    return R_altrep_data2(alt_);
-  }
+  static SEXP Serialized_state(SEXP alt_) { return 
R_altrep_data2(Materialize(alt_)); }
 
   static SEXP Unserialize(SEXP /* class_ */, SEXP state) { return state; }
 
-  SEXP Coerce(int type) {
-    // Just let R handle it for now
-    return NULL;
+  static SEXP Coerce(SEXP alt_, int type) {
+    return Rf_coerceVector(Materialize(alt_), type);
+  }
+
+  static std::shared_ptr<arrow::compute::ScalarAggregateOptions> NaRmOptions(
+      const std::shared_ptr<Array>& array, bool na_rm) {
+    auto options = std::make_shared<arrow::compute::ScalarAggregateOptions>(
+        arrow::compute::ScalarAggregateOptions::Defaults());
+    options->min_count = 0;
+    options->skip_nulls = na_rm;
+    return options;
+  }
+
+  template <bool Min>
+  static SEXP MinMax(SEXP alt_, Rboolean narm) {
+    using data_type = typename std::conditional<sexp_type == REALSXP, double, 
int>::type;
+    using scalar_type =
+        typename std::conditional<sexp_type == INTSXP, Int32Scalar, 
DoubleScalar>::type;
+
+    const auto& array_ = array(alt_);
+    bool na_rm = narm == TRUE;
+    auto n = array_->length();
+    auto null_count = array_->null_count();
+    if ((na_rm || n == 0) && null_count == n) {
+      return Rf_ScalarReal(Min ? R_PosInf : R_NegInf);

Review comment:
       This is what R does: 
   
   ``` r
   min(numeric())
   #> Warning in min(numeric()): no non-missing arguments to min; returning Inf
   #> [1] Inf
   max(numeric())
   #> Warning in max(numeric()): no non-missing arguments to max; returning -Inf
   #> [1] -Inf
   
   min(c(NA_real_, NA_real_), na.rm = TRUE)
   #> Warning in min(c(NA_real_, NA_real_), na.rm = TRUE): no non-missing 
arguments to
   #> min; returning Inf
   #> [1] Inf
   max(c(NA_real_, NA_real_), na.rm = TRUE)
   #> Warning in max(c(NA_real_, NA_real_), na.rm = TRUE): no non-missing 
arguments to
   #> max; returning -Inf
   #> [1] -Inf
   ```
   
   <sup>Created on 2021-09-29 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.0)</sup>




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to