ChanithaAbey opened a new pull request, #55839:
URL: https://github.com/apache/arrow/pull/55839

   ### Rationale for this change
   
   `make_cast_options()` in `r/src/compute.cpp` only forwarded three of the six 
`CastOptions` fields (`allow_int_overflow`, `allow_time_truncate`, 
`allow_float_truncate`) to C++, and only when they were `TRUE`. 
`allow_time_overflow`, `allow_decimal_truncate` and `allow_invalid_utf8` were 
silently ignored, so for example `cast(x, int32(), allow_decimal_truncate = 
TRUE)` still errored on decimals with a fractional part, and `safe = FALSE` did 
not fully disable safety checks.
   
   ### What changes are included in this PR?
   
   - `make_cast_options()` now forwards all six boolean cast options, and 
respects an explicit `FALSE` (previously only `TRUE` was applied).
   - `cast_options(safe = FALSE)` now sets all six options to `TRUE`, matching 
`CastOptions::Unsafe()` in C++.
   - Updated the `cast_options()` documentation to list all options.
   
   ### Are these changes tested?
   
   Yes. Added tests in `test-Array.R` covering `allow_decimal_truncate`, 
`allow_invalid_utf8` and `allow_time_overflow` (default error, option set to 
`TRUE`, `safe = FALSE`, and explicit `FALSE` overriding `safe = FALSE`), plus a 
test for the list returned by `cast_options()`. The new cast test fails without 
the C++ change. Locally (Windows, R 4.6.2), `test-Array.R`, 
`test-dplyr-funcs-type.R`, `test-chunked-array.R`, `test-scalar.R`, 
`test-Table.R`, `test-RecordBatch.R` and `test-expression.R` pass.
   
   ### Are there any user-facing changes?
   
   Yes:
   - `allow_time_overflow`, `allow_decimal_truncate` and `allow_invalid_utf8` 
passed to `$cast()` / `cast()` now take effect.
   - `safe = FALSE` now also allows time overflow, decimal truncation and 
invalid UTF-8.
   - In dplyr queries, `as.integer()` and `bit64::as.integer64()` already 
passed `allow_decimal_truncate = TRUE`; that is now honoured, so decimals with 
a fractional part are truncated instead of raising an error.
   
   ### Was AI used for this PR?
   
   In accordance to the [AI generation 
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
 please disclose below whether and how AI was used in this PR.
   
   **PR code and description written by:**
   
   - [ ] Human
   - [x] AI
   
   **Reviewed before submission by:**
   
   - [x] Human
   - [x] AI
   - [ ] Not reviewed
   
   * GitHub Issue: #20395
   


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