paleolimbot commented on a change in pull request #11612:
URL: https://github.com/apache/arrow/pull/11612#discussion_r745594596



##########
File path: r/tests/testthat/test-dplyr-summarize.R
##########
@@ -879,3 +879,20 @@ test_that("summarize() handles group_by .drop", {
     )
   )
 })
+
+test_that("summarise() passes through type information for temporary columns", 
{
+  # applies to ifelse and case_when(), in which argument types are checked
+  # within a translated function (previously this failed because the 
appropriate
+  # schema was not available for n() > 1, mean(y), and mean(z))
+  compare_dplyr_binding(
+    .input %>%
+      group_by(x) %>%
+      summarise(r = ifelse(n() > 1, mean(y), mean(z))) %>%
+      collect(),
+    tibble(
+      x = c(0, 1, 1),
+      y = c(2, 3, 5),
+      z = c(8, 13, 21)
+    )
+  )

Review comment:
       Your example is fixed by this PR! The first example with `new_col` makes 
sense to fail because it would produce a length != 1 result. I'll add the first 
example to the issue about error messages in summarise.
   
   <details>
   
   ``` r
   # remotes::install_github("apache/arrow/r#11612)
   library(arrow, warn.conflicts = FALSE)
   library(dplyr, warn.conflicts = FALSE)
   
   tab <- Table$create(starwars)
   
   tab %>% 
     group_by(gender) %>% 
     summarise(
       height_mean = mean(height, na.rm = TRUE),
       height_median = median(height, na.rm = TRUE),
       height_evil_avg = if_else(
         height_mean > 178, 
         mean(height, na.rm = TRUE), 
         as.double(median(height, na.rm = TRUE))
       )) %>%
     collect()
   #> Warning: median() currently returns an approximate median in Arrow
   
   #> Warning: median() currently returns an approximate median in Arrow
   #> # A tibble: 3 × 4
   #>   gender    height_mean height_median height_evil_avg
   #>   <chr>           <dbl>         <dbl>           <dbl>
   #> 1 masculine        177.          183             183 
   #> 2 feminine         165.          166.            166.
   #> 3 <NA>             181.          183             181.
   ```
   
   
   </details>




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