dragosmg commented on code in PR #13190:
URL: https://github.com/apache/arrow/pull/13190#discussion_r890964832
##########
r/tests/testthat/test-dplyr-funcs-datetime.R:
##########
@@ -50,49 +50,72 @@ test_df <- tibble::tibble(
test_that("strptime", {
t_string <- tibble(x = c("2018-10-07 19:04:05", NA))
t_stamp <- tibble(x = c(lubridate::ymd_hms("2018-10-07 19:04:05"), NA))
+ t_stamp_with_pm_tz <- tibble(
+ x = c(lubridate::ymd_hms("2018-10-07 19:04:05", tz = "Pacific/Marquesas"),
NA)
+ )
+
+ # base::strptime returns a POSIXlt (a list) => we cannot use
compare_dplyr_binding
+ # => we use expect_equal
+ withr::with_timezone("Pacific/Marquesas", {
+ expect_equal(
+ t_string %>%
+ record_batch() %>%
+ mutate(
+ x = strptime(x, format = "%Y-%m-%d %H:%M:%S")
+ ) %>%
+ collect(),
+ t_stamp_with_pm_tz
+ )
+ })
+
+ expect_equal(
+ t_string %>%
+ arrow_table() %>%
+ mutate(
+ x = strptime(x, format = "%Y-%m-%d %H:%M:%S", tz = "Pacific/Marquesas")
+ ) %>%
+ collect(),
+ t_stamp_with_pm_tz
+ )
expect_equal(
t_string %>%
Table$create() %>%
mutate(
- x = strptime(x)
+ x = strptime(x, tz = "UTC")
) %>%
collect(),
- t_stamp,
- ignore_attr = "tzone"
+ t_stamp
)
expect_equal(
t_string %>%
Table$create() %>%
mutate(
- x = strptime(x, format = "%Y-%m-%d %H:%M:%S")
+ x = strptime(x, format = "%Y-%m-%d %H:%M:%S", tz = "UTC")
) %>%
collect(),
- t_stamp,
- ignore_attr = "tzone"
+ t_stamp
)
expect_equal(
t_string %>%
Table$create() %>%
mutate(
- x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "ns")
+ x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "ns", tz = "UTC")
) %>%
collect(),
- t_stamp,
- ignore_attr = "tzone"
+ t_stamp
)
expect_equal(
t_string %>%
Table$create() %>%
mutate(
- x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "s")
+ x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "s", tz = "UTC")
Review Comment:
I added a comment and renamed one of the test tibbles. Hopefully that helps.
--
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]