Skip to content

[R] Date Inf/ -Inf silently corrupted when converting to Arrow date32 #49836

Open

Description

@dragosmg

Describe the bug, including details regarding any error messages, version, and platform.

I am not 100% convinced this is a bug or rather some unexpected behaviour.

When an R Date vector contains Inf or -Inf, converting to an Arrow table (e.g. via as_arrow_table() or write_parquet()) silently converts these to extreme, but finite, dates instead of null or raising an error.

Reprex:

library(arrow)
library(tibble)
library(dplyr)

tibble(x = as.Date(c(Inf, -Inf))) |> 
    as_arrow_table() |> 
    collect()
#> # A tibble: 2 × 1
#>   x             
#>   <date>        
#> 1 5881580-07-11 
#> 2 -5877641-06-23

Second example (includes NaN):

library(arrow)
library(tibble)
library(dplyr)

chunks <- tibble(x = as.Date(c(Inf, -Inf, NaN))) |> 
  as_arrow_table()

chunks$columns
#> [[1]]
#> ChunkedArray
#> <date32[day]>
#> [
#>   [
#>     <value out of range: 2147483647>,
#>     <value out of range: -2147483648>,
#>     1970-01-01
#>   ]
#> ]

A final reprex to highlight the problematic aspect of casting to int32 which results in NA_integer_ clashing with INT_MIN:

library(arrow)
library(tibble)
library(dplyr)

tibble(x = as.Date(c(Inf, -Inf, NaN))) |> 
  as_arrow_table() |> 
  collect() |> 
  mutate(y = as.integer(x))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `y = as.integer(x)`.
#> Caused by warning:
#> ! NAs introduced by coercion to integer range
#> # A tibble: 3 × 2
#>   x                       y
#>   <date>              <int>
#> 1 5881580-07-11  2147483647
#> 2 -5877641-06-23         NA
#> 3 1970-01-01              0

Expected behaviour:
I think it might be better if Inf/-Inf dates are either converted to null in the Arrow array, or the conversion should error/warn indicating that infinite date values are not representable in date32.

Root cause:
In https://github.com/apache/arrow/blob/main/r/src/r_to_arrow.cpp#L600, FromRdate for Date32Type does:

  static int FromRDate(const Date32Type*, double from) {
    return static_cast<int>(std::floor(from));
  }

As far as I understand, static_cast<int>(std::floor(Inf)) is undefined behaviour in C++. On most platforms this would produce INT_MAX/ INT_MIN, which Arrow then interprets as concrete dates ~5.8 million years from epoch.

A possible fix would be to check for non-finite values before the cast:

static int FromRDate(const Date32Type*, double from) {
    if (!std::infinite(from)) {
        // handle as null or error/ warn
    }
    return static_cast<int>(std::floor(from));
  }

NaN date are also affected by the same behaviour. Arguably more problematic as the roundtrip transforms them into 0 (i.e. epoch).

Component(s)

R

Activity

  1. changed the title [-]R Date `Inf`/ `-Inf` silently corrupted when converting to Arrow `date32`[/-] [+][R] Date `Inf`/ `-Inf` silently corrupted when converting to Arrow `date32`[/+] on Apr 30, 2026
  2. thisisnic commented on May 5, 2026

    @thisisnic
    Member

    Thanks for reporting this! Can reproduce in dev arrow. Want to submit a PR @dragosmg ?

  3. richarddmorey commented on May 6, 2026

    @richarddmorey

    Adding a +1 to this; was about to make a bug report but noticed that this had already been raised. Thanks @dragosmg.

    Oddly, I have a slightly different result; I am getting dates far in the past for Inf as well as -Inf, when using {lubridate}:

    library(dplyr)
    #> Warning: package 'dplyr' was built under R version 4.5.3
    #> 
    #> Attaching package: 'dplyr'
    #> The following objects are masked from 'package:stats':
    #> 
    #>     filter, lag
    #> The following objects are masked from 'package:base':
    #> 
    #>     intersect, setdiff, setequal, union
    library(lubridate)
    #> Warning: package 'lubridate' was built under R version 4.5.3
    #> 
    #> Attaching package: 'lubridate'
    #> The following objects are masked from 'package:base':
    #> 
    #>     date, intersect, setdiff, union
    
    tibble(
      date = c(
        ymd("2008/01/01"),
        as_date(-Inf),
        as_date(Inf)
      )
    ) -> x
    
    # Seems to act reasonably
    x$date > ymd("2007/01/01")
    #> [1]  TRUE FALSE  TRUE
    is.infinite(x$date)
    #> [1] FALSE  TRUE  TRUE
    
    tf = tempfile(fileext = ".feather")
    arrow::write_feather(x = x, sink = tf)
    x_arrow = arrow::read_feather(tf)
    
    x
    #> # A tibble: 3 × 1
    #>   date      
    #>   <date>    
    #> 1 2008-01-01
    #> 2 -Inf      
    #> 3 Inf
    
    x_arrow
    #> # A tibble: 3 × 1
    #>   date          
    #>   <date>        
    #> 1 2008-01-01    
    #> 2 -5877641-06-23
    #> 3 -5877641-06-23
    
    # This is no longer correct
    x_arrow$date > ymd("2007/01/01")
    #> [1]  TRUE FALSE FALSE
    
    xfun::session_info()
    #> R version 4.5.1 (2025-06-13 ucrt)
    #> Platform: x86_64-w64-mingw32/x64
    #> Running under: Windows 11 x64 (build 26200)
    #> 
    #> Locale:
    #>   LC_COLLATE=English_United States.utf8 
    #>   LC_CTYPE=English_United States.utf8   
    #>   LC_MONETARY=English_United States.utf8
    #>   LC_NUMERIC=C                          
    #>   LC_TIME=English_United States.utf8    
    #> 
    #> Package version:
    #>   arrow_24.0.0      assertthat_0.2.1  base64enc_0.1.6   bit_4.6.0        
    #>   bit64_4.6.0-1     bslib_0.10.0      cachem_1.1.0      callr_3.7.6      
    #>   cli_3.6.5         clipr_0.8.0       compiler_4.5.1    cpp11_0.5.3      
    #>   digest_0.6.39     dplyr_1.2.1       evaluate_1.0.5    fastmap_1.2.0    
    #>   fontawesome_0.5.3 fs_1.6.7          generics_0.1.4    glue_1.8.0       
    #>   graphics_4.5.1    grDevices_4.5.1   highr_0.12        htmltools_0.5.9  
    #>   jquerylib_0.1.4   jsonlite_2.0.0    knitr_1.51        lifecycle_1.0.5  
    #>   lubridate_1.9.5   magrittr_2.0.4    memoise_2.0.1     methods_4.5.1    
    #>   mime_0.13         otel_0.2.0        pillar_1.11.1     pkgconfig_2.0.3  
    #>   processx_3.8.6    ps_1.9.1          purrr_1.1.0       R6_2.6.1         
    #>   rappdirs_0.3.4    reprex_2.1.1      rlang_1.1.7       rmarkdown_2.30   
    #>   rstudioapi_0.18.0 sass_0.4.10       stats_4.5.1       tibble_3.3.0     
    #>   tidyselect_1.2.1  timechange_0.4.0  tinytex_0.58      tools_4.5.1      
    #>   tzdb_0.5.0        utf8_1.2.6        utils_4.5.1       vctrs_0.7.1      
    #>   withr_3.0.2       xfun_0.56         yaml_2.3.12
  4. added
    Status: needs champion
    on Oct 26, 2026
  5. added
    Status: confirmed
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: RStatus: confirmedStatus: needs championType: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions