jonkeane commented on a change in pull request #12402:
URL: https://github.com/apache/arrow/pull/12402#discussion_r837926108
##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -118,6 +118,51 @@ test_that("errors in strptime", {
)
})
+test_that("strptime returns NA when format doesn't match the data", {
+ df <- tibble(
+ str_date = c("2022-02-07", "2012/02-07", "1975/01-02", "1981/01-07")
+ )
+
+ expect_equal(
+ df %>%
+ arrow_table() %>%
+ mutate(
+ r_obj_parsed_date = strptime("03-27/2022", format = "%m-%d/%Y"),
+ r_obj_parsed_na = strptime("03-27/2022", format = "Y%-%m-%d")) %>%
+ collect(),
+ tibble(
+ str_date = c("2022-02-07", "2012/02-07", "1975/01-02", "1981/01-07"),
+ r_obj_parsed_date = as.POSIXct(rep("2022-03-27", 4)),
+ r_obj_parsed_na = as.POSIXct(rep(NA, 4))
+ ),
+ ignore_attr = "tzone"
+ )
Review comment:
Ah right right. It's a bit more verbose, but what about doing something
like:
```
expect_equal(
df %>%
arrow_table() %>%
mutate(
r_obj_parsed_date = strptime("03-27/2022", format = "%m-%d/%Y"),
r_obj_parsed_na = strptime("03-27/2022", format = "Y%-%m-%d")) %>%
collect(),
df %>%
arrow_table() %>%
mutate(
r_obj_parsed_date = as.POSIXct(strptime("03-27/2022", format =
"%m-%d/%Y")),
r_obj_parsed_na = as.POSIXct(strptime("03-27/2022", format =
"Y%-%m-%d")))
ignore_attr = "tzone"
)
```
Along with a comment explaining what's going on?
--
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]