thisisnic commented on a change in pull request #11105:
URL: https://github.com/apache/arrow/pull/11105#discussion_r710868139
##########
File path: r/tests/testthat/test-dplyr-string-functions.R
##########
@@ -719,6 +719,40 @@ test_that("errors in strptime", {
)
})
+test_that("strftime", {
+ skip_on_os("windows") # https://issues.apache.org/jira/browse/ARROW-13168
+
+ # TODO: consider reevaluating this workaround after ARROW-12980
+ withr::local_timezone("UTC")
+ times <- tibble(x = c(lubridate::ymd_hms("2018-10-07 19:04:05"), NA))
+
+ formats = c("%a", "%A", "%w", "%d", "%b", "%B", "%m", "%y", "%Y", "%H",
+ "%I", "%p", "%M", "%z", "%Z", "%j", "%U", "%W", "%c", "%x",
+ "%X", "%%", "%G", "%V", "%u")
+
+ for (format in formats) {
+ expect_dplyr_equal(
+ input %>%
+ mutate(x = strftime(x, format = format)) %>%
+ collect(),
+ times
+ )
+
+ expect_dplyr_equal(
+ input %>%
+ mutate(x = strftime(x, format = format, usetz = TRUE)) %>%
+ collect(),
+ times
+ )
+
+ x <- Expression$field_ref("x")
+ expect_error(
+ nse_funcs$strftime(x, format = format, tz="Mars/Mariner_Valley"),
+ "tz argument not supported by Arrow"
+ )
+ }
+})
Review comment:
How about something like this? It's not complete - the final two format
tests are still causing problems, but it's a starting point.
```suggestion
df <- tibble(x = c(lubridate::ymd_hms("2019-02-03 12:34:56"), NA))
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%a %A %w %d %b")) %>%
collect(),
df
)
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%B %m %y %Y %H")) %>%
collect(),
df
)
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%I %p %M %j")) %>%
collect(),
df
)
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%U %W %c %x")) %>%
collect(),
df
)
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%X %% %G %V %u")) %>%
collect(),
df
)
# Needs updating to deal with the difference in precision
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%S")) %>%
collect(),
df
)
# we should do something around documenting or dealing with this difference
too
withr::with_timezone("Pacific/Marquesas",
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%z %Z ")) %>%
collect(),
df
)
)
# we also need to do something about this
withr::with_timezone("Pacific/Marquesas",
expect_dplyr_equal(
input %>%
mutate(x = strftime(x, format = "%H", usetz = TRUE)) %>%
collect(),
df
)
)
x <- Expression$field_ref("x")
expect_error(
nse_funcs$strftime(x, format = format, tz="Mars/Mariner_Valley"),
"tz argument not supported by Arrow"
)
})
```
--
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]