paleolimbot commented on pull request #11133:
URL: https://github.com/apache/arrow/pull/11133#issuecomment-917306807


   Fixed the base with length != 1 issue, although I think my error message 
could be better since base with length != 1 *is* supported, just not as a 
non-expression. Reprex summary of new functionality:
   
   ``` r
   library(arrow)
   library(dplyr, warn.conflicts = FALSE)
   
   # with base as a column
   RecordBatch$create(a = 2:5, b = 2:5) %>% 
     mutate(log(a, base = b)) %>% 
     collect()
   #> # A tibble: 4 × 3
   #>       a     b `log(a, base = b)`
   #>   <int> <int>              <dbl>
   #> 1     2     2                  1
   #> 2     3     3                  1
   #> 3     4     4                  1
   #> 4     5     5                  1
   # with base as a scalar
   RecordBatch$create(a = 2:5) %>% 
     mutate(log(a, base = 3)) %>% 
     collect()
   #> # A tibble: 4 × 2
   #>       a `log(a, base = 3)`
   #>   <int>              <dbl>
   #> 1     2              0.631
   #> 2     3              1    
   #> 3     4              1.26 
   #> 4     5              1.46
   # errors for base with length != 1
   RecordBatch$create(a = 2:5) %>% 
     mutate(log(a, base = 3:4)) %>% 
     collect()
   #> Warning: In log(a, base = 3:4), base with length != 1 not supported by 
Arrow;
   #> pulling data into R
   #> # A tibble: 4 × 2
   #>       a `log(a, base = 3:4)`
   #>   <int>                <dbl>
   #> 1     2                0.631
   #> 2     3                0.792
   #> 3     4                1.26 
   #> 4     5                1.16
   ```
   
   Should `x` as a scalar be supported? It currently triggers bringing the data 
in to R but could theoretically not:
   
   ``` r
   
   # errors
   RecordBatch$create(a = 2:5) %>% 
     mutate(a * log(2)) %>% 
     collect()
   #> Warning: Expression a * log(2) not supported in Arrow; pulling data into R
   #> # A tibble: 4 × 2
   #>       a `a * log(2)`
   #>   <int>        <dbl>
   #> 1     2         1.39
   #> 2     3         2.08
   #> 3     4         2.77
   #> 4     5         3.47
   # works!
   RecordBatch$create(a = 2:5) %>% 
     mutate(a * log(Expression$scalar(2))) %>% 
     collect()
   #> # A tibble: 4 × 2
   #>       a `a * log(Expression$scalar(2))`
   #>   <int>                           <dbl>
   #> 1     2                            1.39
   #> 2     3                            2.08
   #> 3     4                            2.77
   #> 4     5                            3.47
   ```
   
   


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