ianmcook commented on a change in pull request #11794:
URL: https://github.com/apache/arrow/pull/11794#discussion_r758783680
##########
File path: r/tests/testthat/test-dplyr-funcs-conditional.R
##########
@@ -116,18 +116,17 @@ test_that("if_else and ifelse", {
tbl
)
- # TODO: remove the mutate + warning after ARROW-13358 is merged and Arrow
- # supports factors in if(_)else
compare_dplyr_binding(
.input %>%
mutate(
y = if_else(int > 5, fct, factor("a"))
) %>%
collect() %>%
- # This is a no-op on the Arrow side, but necessary to make the results
equal
- mutate(y = as.character(y)),
- tbl,
- warning = "Dictionaries .* are currently converted to strings .* in
if_else and ifelse"
+ # Arrow if_else() kernel does not preserve unused factor levels,
+ # so reset the levels of all the factor columns to make the test pass
+ # (ARROW-14649)
+ transmute(across(where(is.factor), ~ factor(.x, levels = c("a", "b",
"c")))),
Review comment:
Let's add all the factor levels that are present in `tbl$fct` to avoid
creating missing values in the output.
```suggestion
transmute(across(where(is.factor), ~ factor(.x, levels = c("a", "b",
"c", "d", "g", "h", "i", "j")))),
```
--
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]