jonkeane commented on a change in pull request #12429: URL: https://github.com/apache/arrow/pull/12429#discussion_r808112466
########## File path: r/tests/testthat/test-dplyr-funcs-datetime.R ########## @@ -711,3 +711,48 @@ test_that("am/pm mirror lubridate", { ) }) + +test_that("semester works with temporal types", { + test_df <- tibble( + month_as_int = c(1:12, NA), + month_as_char_pad = ifelse(month_as_int < 10, paste0("0", month_as_int), month_as_int), + dates = as.Date(paste0("2021-", month_as_char_pad, "-15")) + ) Review comment: I see this repeated down below as well and we don't use all of the inputs here. We should either curate the inputs so that this tibble has all and only the columns that are used in this block (and same with the one below) or we should factor these out + put them up top or somewhere else such that we define it once and then use it in multiple `test_that` blocks. ########## File path: r/tests/testthat/test-dplyr-funcs-datetime.R ########## @@ -711,3 +711,48 @@ test_that("am/pm mirror lubridate", { ) }) + +test_that("semester works with temporal types", { + test_df <- tibble( + month_as_int = c(1:12, NA), + month_as_char_pad = ifelse(month_as_int < 10, paste0("0", month_as_int), month_as_int), + dates = as.Date(paste0("2021-", month_as_char_pad, "-15")) + ) + + # test extraction from dates + compare_dplyr_binding( + .input %>% + mutate(sem_wo_year = semester(dates), + sem_w_year = semester(dates, with_year = TRUE)) %>% + collect(), + test_df + ) +}) + +test_that("semester errors with integers and characters", { + test_df <- tibble( + month_as_int = c(1:12, NA), + month_as_char_pad = ifelse(month_as_int < 10, paste0("0", month_as_int), month_as_int), + dates = as.Date(paste0("2021-", month_as_char_pad, "-15")) + ) + + # extraction from integers should error as we currently do not support setting + # month components with month, but this is supported by `lubridate::month()` + # this should no longer fail once https://issues.apache.org/jira/browse/ARROW-15701 + # is addressed Review comment: Thanks for adding this in as a comment here! It's minor, but makes it easier to find them later, I try and add a `# TODO: ...` line somewhere in these blocks (ideally on the line that has the jira ticket number) ########## File path: r/tests/testthat/test-dplyr-funcs-datetime.R ########## @@ -711,3 +711,48 @@ test_that("am/pm mirror lubridate", { ) }) + +test_that("semester works with temporal types", { + test_df <- tibble( + month_as_int = c(1:12, NA), + month_as_char_pad = ifelse(month_as_int < 10, paste0("0", month_as_int), month_as_int), + dates = as.Date(paste0("2021-", month_as_char_pad, "-15")) + ) + + # test extraction from dates + compare_dplyr_binding( + .input %>% + mutate(sem_wo_year = semester(dates), + sem_w_year = semester(dates, with_year = TRUE)) %>% + collect(), + test_df + ) +}) + +test_that("semester errors with integers and characters", { + test_df <- tibble( + month_as_int = c(1:12, NA), + month_as_char_pad = ifelse(month_as_int < 10, paste0("0", month_as_int), month_as_int), Review comment: ```suggestion month_as_char_pad = sprintf("%02i", month_as_int), ``` This gets what you need here, yeah? -- 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