jonkeane commented on a change in pull request #12482:
URL: https://github.com/apache/arrow/pull/12482#discussion_r822765160
##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -820,6 +816,81 @@ test_that("dst extracts daylight savings time correctly", {
)
})
+test_that("month() supports integer input", {
+ test_df_month <- tibble(
+ month_as_int = c(1:12, NA)
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(month_int_input = month(month_as_int)) %>%
+ collect(),
+ test_df_month
+ )
+
+ skip_on_os("windows") # https://issues.apache.org/jira/browse/ARROW-13168
+
+ compare_dplyr_binding(
+ .input %>%
+ # R returns ordered factor whereas Arrow returns character
+ mutate(
+ month_int_input = as.character(month(month_as_int, label = TRUE))
+ ) %>%
+ collect(),
+ test_df_month
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ # R returns ordered factor whereas Arrow returns character
+ mutate(
+ month_int_input = as.character(
+ month(month_as_int, label = TRUE, abbr = FALSE)
+ )
+ ) %>%
+ collect(),
+ test_df_month
+ )
+ })
+
+test_that("month() errors with double input and returns NA with int outside
1:12", {
+ test_df_month <- tibble(
+ month_as_int = c(-1L, 1L, 13L, NA),
+ month_as_double = month_as_int + 0.1
+ )
+
+ expect_equal(
+ test_df_month %>%
+ arrow_table() %>%
+ select(month_as_int) %>%
+ mutate(month_int_input = month(month_as_int)) %>%
+ collect(),
+ tibble(
+ month_as_int = c(-1L, 1L, 13L, NA),
+ month_int_input = c(NA, 1L, NA, NA)
+ )
+ )
+
+ expect_error(
+ test_df_month %>%
+ arrow_table() %>%
+ mutate(month_dbl_input = month(month_as_double)) %>%
+ collect(),
+ regexp = "Function 'month' has no kernel matching input types
(array[double])",
+ fixed = TRUE
+ )
+
+ expect_error(
+ test_df_month %>%
+ record_batch() %>%
+ mutate(month_dbl_input = month(month_as_double)) %>%
+ collect(),
+ regexp = "Function 'month' has no kernel matching input types
(array[double])",
+ fixed = TRUE
+ )
+
Review comment:
```suggestion
```
--
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]