paleolimbot commented on issue #40194:
URL: https://github.com/apache/arrow/issues/40194#issuecomment-1972328275

   Reprex:
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   
   arrow_array("-2147483648")$cast(int32()) |> as.vector()
   #> [1] NA
   ```
   
   This conversion happens in one of a few places, depending on whether 
`options(arrow.use_altrep = TRUE)` and how the caller of the R C API is 
consuming the ALTREP array (by `INTEGER_ELT()`, `INTEGER_GET_REGION()`, or 
`DATAPTR_RO()`.
   
   
https://github.com/apache/arrow/blob/214378b522a36fbf6010e3d4f5470abaca7bf92e/r/src/array_to_vector.cpp#L193
   
   
https://github.com/apache/arrow/blob/214378b522a36fbf6010e3d4f5470abaca7bf92e/r/src/altrep.cpp#L282-L283
   
   
https://github.com/apache/arrow/blob/214378b522a36fbf6010e3d4f5470abaca7bf92e/r/src/altrep.cpp#L310-L311
   
   
https://github.com/apache/arrow/blob/214378b522a36fbf6010e3d4f5470abaca7bf92e/r/src/altrep.cpp#L259-L262
   
   Checking for specific int32 values is potentially expensive (but safer) in 
the ALTREP scenario...technically there would be an identical problem with 
int64 conversions to R's integer64 class.
   
   It looks like nanoarrow has an identical problem here:
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   
   arrow_array("-2147483648")$cast(int32()) |>
     nanoarrow::as_nanoarrow_array() |> 
     as.vector()
   #> [1] NA
   ```
   


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