You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Jonathan Keane (Jira)" <ji...@apache.org> on 2021/11/19 16:32:00 UTC

[jira] [Created] (ARROW-14778) [C++] mean on a decimal truncates and does not round

Jonathan Keane created ARROW-14778:
--------------------------------------

             Summary: [C++] mean on a decimal truncates and does not round
                 Key: ARROW-14778
                 URL: https://issues.apache.org/jira/browse/ARROW-14778
             Project: Apache Arrow
          Issue Type: Bug
          Components: C++
            Reporter: Jonathan Keane


{code}
library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)

df <- data.frame(
  x = c(0.1, 0.2, 0.2, 0.2, 0.2)
)

tab <- Table$create(df)

tab %>%
  summarise(mean(x)) %>% 
  collect()
#> # A tibble: 1 × 1
#>   `mean(x)`
#>       <dbl>
#> 1      0.18

tab %>%
  summarise(x = mean(x)) %>% 
  mutate(x = cast(x, decimal(5, 1))) %>% 
  collect()
#> # A tibble: 1 × 1
#>       x
#>   <dbl>
#> 1   0.2

tab %>%
  mutate(x = cast(x, decimal(5, 1))) %>% 
  summarise(x = mean(x)) %>% 
  collect()
#> # A tibble: 1 × 1
#>       x
#>   <dbl>
#> 1   0.1
{code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)