Repository navigation
GH-20395: [R] Allow all cast options to be specified - #55839
Open
ChanithaAbey wants to merge 2 commits into
Open
ChanithaAbey wants to merge 2 commits into
ChanithaAbey wants to merge 2 commits into
Conversation
make_cast_options() only forwarded allow_int_overflow, allow_time_truncate and allow_float_truncate to C++, and only when they were TRUE. allow_time_overflow, allow_decimal_truncate and allow_invalid_utf8 were silently ignored. Forward all six CastOptions fields, honour explicit FALSE values, and have cast_options(safe = FALSE) enable every option.
…e decimals in dplyr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
make_cast_options()inr/src/compute.cpponly forwarded three of the sixCastOptionsfields (allow_int_overflow,allow_time_truncate,allow_float_truncate) to C++, and only when they wereTRUE.allow_time_overflow,allow_decimal_truncateandallow_invalid_utf8were silently ignored, so for examplecast(x, int32(), allow_decimal_truncate = TRUE)still errored on decimals with a fractional part, andsafe = FALSEdid 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 explicitFALSE(previously onlyTRUEwas applied).cast_options(safe = FALSE)now sets all six options toTRUE, matchingCastOptions::Unsafe()in C++.cast_options()documentation to list all options.Are these changes tested?
Yes. Added tests in
test-Array.Rcoveringallow_decimal_truncate,allow_invalid_utf8andallow_time_overflow(default error, option set toTRUE,safe = FALSE, and explicitFALSEoverridingsafe = FALSE), plus a test for the list returned bycast_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.Randtest-expression.Rpass.Are there any user-facing changes?
Yes:
allow_time_overflow,allow_decimal_truncateandallow_invalid_utf8passed to$cast()/cast()now take effect.safe = FALSEnow also allows time overflow, decimal truncation and invalid UTF-8.as.integer()andbit64::as.integer64()already passedallow_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, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by: