Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-14778

[C++] mean on a decimal truncates and does not round

    XMLWordPrintableJSON

Details

    Description

      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
      

      Attachments

        Issue Links

          Activity

            People

              lidavidm David Li
              jonkeane Jonathan Keane
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 50m
                  2h 50m