nealrichardson commented on a change in pull request #10724: URL: https://github.com/apache/arrow/pull/10724#discussion_r671580198
########## File path: r/tests/testthat/test-dplyr.R ########## @@ -1013,44 +1013,158 @@ test_that("log functions", { ) }) - + test_that("trig functions", { - + df <- tibble(x = c(seq(from = 0, to = 1, by = 0.1), NA)) - + expect_dplyr_equal( input %>% mutate(y = sin(x)) %>% collect(), df ) - + expect_dplyr_equal( input %>% mutate(y = cos(x)) %>% collect(), df ) - + expect_dplyr_equal( input %>% mutate(y = tan(x)) %>% collect(), df ) - + expect_dplyr_equal( input %>% mutate(y = asin(x)) %>% collect(), df ) - + expect_dplyr_equal( input %>% mutate(y = acos(x)) %>% collect(), df ) -}) \ No newline at end of file +}) + +test_that("if_else and ifelse", { + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, 1, 0) + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, int, 0L) + ) %>% collect(), + example_data + ) + + expect_error( + Table$create(example_data) %>% + mutate( + y = if_else(int > 5, 1, FALSE) + ) %>% collect(), + 'NotImplemented: Function if_else has no kernel matching input types' + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, 1, NA_real_) + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = ifelse(int > 5, 1, 0) + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(dbl > 5, TRUE, FALSE) + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(chr %in% letters[1:3], 1L, 3L) + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, "one", "zero") + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, chr, chr) + ) %>% collect(), + example_data + ) + + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, chr, chr, missing = "MISSING") + ) %>% collect(), + example_data + ) + + # TODO: remove the mutate + warning after ARROW-13358 is merged and Arrow + # supports factors in if(_)else + expect_dplyr_equal( + input %>% + mutate( + y = if_else(int > 5, fct, factor("a")) + ) %>% collect() %>% + # This is a no-op on the Arrow side, but necesary to make the results equal + mutate(y = as.character(y)), + example_data, + warning = "Factors are currently converted to characters in if_else and ifelse" + ) + + skip("ARROW-12055 for better NaN support") + # currently NaNs are not NAs and so the missing argument is not correctly + # applied + expect_dplyr_equal( + input %>% + mutate( + y = if_else(dbl > 5, chr, chr, missing = "MISSING") + ) %>% collect(), + example_data_for_sorting + ) Review comment: Gosh, missing data is hard 🤔 -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org