Copilot commented on code in PR #51292:
URL: https://github.com/apache/arrow/pull/51292#discussion_r3981890222
##########
r/R/dplyr-funcs-simple.R:
##########
@@ -188,6 +188,13 @@ common_type <- function(exprs) {
}
cast_or_parse <- function(x, type) {
+ # A null scalar (e.g. a bare `NA`, which is logical) carries no data, so
+ # skip the value cast and just create a null of the target type. This
+ # avoids unsupported casts like bool -> date32 (GH-38358).
+ if (!x$is_valid) {
+ return(Scalar$create(NULL)$cast(type))
+ }
+
to_type_id <- type$id
Review Comment:
`cast_or_parse()` is used with both `Scalar` and `Array` inputs (e.g. `%in%`
binding casts `value_set <- Array$create(table)` in
`r/R/dplyr-funcs-conditional.R:194-197`). The new `if (!x$is_valid)` branch
assumes `x` has an `is_valid` active binding, which only exists for `Scalar`;
when `x` is an `Array`, `x$is_valid` is `NULL` and this `if` condition will
error (currently masked by a `try()` in `%in%`, but it prevents intended
casting).
Guard this special-case so it only runs for invalid `Scalar` values.
--
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]