[
https://issues.apache.org/jira/browse/ARROW-14125?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17419910#comment-17419910
]
Ian Cook commented on ARROW-14125:
----------------------------------
I'm not able to repro this with a current development build; perhaps it's
limited to the fork you're working in? Regardless, let's use this Jira to add
an example like this to the {{round()}} tests in {{test-dplyr.R}}.
> [R] Why does round with arithmetic error?
> -----------------------------------------
>
> Key: ARROW-14125
> URL: https://issues.apache.org/jira/browse/ARROW-14125
> Project: Apache Arrow
> Issue Type: Bug
> Reporter: Jonathan Keane
> Priority: Major
>
> Trying to call {{round}} with an arithmetic expression errors / pulls data
> into R:
> {code}
> > library(arrow)
> > library(dplyr)
> >
> > df <- tibble(x = c(-1, -0.55, -0.5, -0.1, 0, 0.1, 0.5, 0.55, 1, NA, NaN))
> >
> > # Round with arith inside pulls into R
> > Table$create(df) %>%
> + mutate(
> + r = round(x + 1)
> + ) %>%
> + collect()
> Warning: Expression round(x + 1) not supported in Arrow; pulling data into R
> # A tibble: 11 × 2
> x r
> <dbl> <dbl>
> 1 -1 0
> 2 -0.55 0
> 3 -0.5 0
> 4 -0.1 1
> 5 0 1
> 6 0.1 1
> 7 0.5 2
> 8 0.55 2
> 9 1 2
> 10 NA NA
> 11 NaN NaN
> >
> > Table$create(df) %>%
> + mutate(
> + r = round(0.00001 + 1)
> + ) %>%
> + collect()
> Warning: Expression round(1e-05 + 1) not supported in Arrow; pulling data
> into R
> # A tibble: 11 × 2
> x r
> <dbl> <dbl>
> 1 -1 1
> 2 -0.55 1
> 3 -0.5 1
> 4 -0.1 1
> 5 0 1
> 6 0.1 1
> 7 0.5 1
> 8 0.55 1
> 9 1 1
> 10 NA 1
> 11 NaN 1
> {code}
> However truncate works just fine:
> {code}
> > Table$create(df) %>%
> + mutate(
> + r = trunc(0.00001 + 1)
> + ) %>%
> + collect()
> # A tibble: 11 × 2
> x r
> <dbl> <dbl>
> 1 -1 1
> 2 -0.55 1
> 3 -0.5 1
> 4 -0.1 1
> 5 0 1
> 6 0.1 1
> 7 0.5 1
> 8 0.55 1
> 9 1 1
> 10 NA 1
> 11 NaN 1
> >
> >
> > Table$create(df) %>%
> + mutate(
> + r = trunc(x + 1)
> + ) %>% collect()
> # A tibble: 11 × 2
> x r
> <dbl> <dbl>
> 1 -1 0
> 2 -0.55 0
> 3 -0.5 0
> 4 -0.1 0
> 5 0 1
> 6 0.1 1
> 7 0.5 1
> 8 0.55 1
> 9 1 2
> 10 NA NA
> 11 NaN NaN
> >
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)