You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Ian Cook (Jira)" <ji...@apache.org> on 2021/09/02 16:38:00 UTC

[jira] [Commented] (ARROW-13799) [R] case_when error handling is capturing strings

    [ https://issues.apache.org/jira/browse/ARROW-13799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17408969#comment-17408969 ] 

Ian Cook commented on ARROW-13799:
----------------------------------

Related to this: we have a binding for {{as.factor()}} that calls the {{dictionary_encode}} kernel. I would expect that using {{as.factor()}} instead of {{factor()}} would solve this, but instead it throws this error:
{code:java}
 Error: Invalid: ExecuteScalarExpression cannot Execute non-scalar expression case_when({1=invert(invert(invert(lgl))), 2=true}, cast(dictionary_encode(chr, {null_encoding_behavior=MASK}), {to_type=string, allow_int_overflow=false, allow_time_truncate=false, allow_time_overflow=false, allow_decimal_truncate=false, allow_float_truncate=false, allow_invalid_utf8=false}), cast(fct, {to_type=string, allow_int_overflow=false, allow_time_truncate=false, allow_time_overflow=false, allow_decimal_truncate=false, allow_float_truncate=false, allow_invalid_utf8=false}))  {code}
Reducing this down to a simpler example:
{code:java}
> Table$create(tbl) %>% mutate(as.factor(chr)) %>% collect()

Error: Invalid: ExecuteScalarExpression cannot Execute non-scalar expression dictionary_encode(chr, {null_encoding_behavior=MASK})  {code}
So it looks like something is going wrong with passing the {{null_encoding_behavior}} option to the {{dictionary_encode}} kernel.

> [R] case_when error handling is capturing strings
> -------------------------------------------------
>
>                 Key: ARROW-13799
>                 URL: https://issues.apache.org/jira/browse/ARROW-13799
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: R
>            Reporter: Neal Richardson
>            Priority: Major
>             Fix For: 6.0.0
>
>
> This test, now unskipped since case_when supports string data, fails:
> {code}
>   expect_dplyr_equal(
>     input %>%
>       mutate(
>         cw = case_when(!(!(!(lgl))) ~ factor(chr), TRUE ~ fct)
>       ) %>%
>       collect(),
>     tbl
>   )
> {code}
> On inspection, it seems that `factor(chr)` is hitting `base::factor()`, which tries to call `unique()` on the Expression and that fails with "unique() applies only to vectors". This is getting propagated through to the resulting dataset column because `arrow_eval()` returns a `try-error` on error and `nse_funcs$case_when()` isn't checking for errors.
> cc [~icook]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)