Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-16415: [R] Update strptime binding signature with the tz argument#13190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aaa43a5
adding `tz` support to `strptime` + updated unit tests
dragosmg 2619723
set default value for `tz` to match `base::strptime()`
dragosmg f9c29a1
update unit tests
dragosmg b42453e
bump ci
dragosmg c27dbf9
bump ci
dragosmg 5525acc
bump ci
dragosmg e34f552
comment + `record_batch()` in one of the tests
dragosmg 8e216aa
added comment on the use of `assume_timezone`
dragosmg ee73795
expanded on why `assume_timezone` is needed
dragosmg f0c3323
improved comments and renamed one of the test tibbles for more clarity
dragosmg ca4e902
forgot about one `t_stamp`
dragosmg 90ce31b
Update r/tests/testthat/test-dplyr-funcs-datetime.R
jonkeane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -49,50 +49,82 @@ 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)) | ||
| # lubridate defaults to "UTC" as timezone => t_stamp is in "UTC" | ||
| t_stamp_with_utc_tz <- 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 for the tests below | ||
| withr::with_timezone("Pacific/Marquesas", { | ||
dragosmg marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # the default value for strptime's `tz` argument is "", which is interpreted | ||
| # as the current timezone. we test here if the strptime binding picks up | ||
| # correctly the current timezone (similarly to the base R version) | ||
| expect_equal( | ||
| t_string %>% | ||
| record_batch() %>% | ||
| mutate( | ||
| x = strptime(x, format = "%Y-%m-%d %H:%M:%S") | ||
| ) %>% | ||
| collect(), | ||
| t_stamp_with_pm_tz | ||
| ) | ||
| }) | ||
| # adding a timezone to a timezone-naive timestamp works | ||
jonkeane marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # and since our TZ when running the test is (typically) Pacific/Marquesas | ||
| # this also tests that assigning a TZ different from the current session one | ||
| # works as expected | ||
| 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_with_utc_tz | ||
| ) | ||
| 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_with_utc_tz | ||
| ) | ||
| 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_with_utc_tz | ||
| ) | ||
| 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") | ||
dragosmg marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) %>% | ||
| collect(), | ||
| t_stamp, | ||
| ignore_attr = "tzone" | ||
| t_stamp_with_utc_tz | ||
| ) | ||
| tstring <- tibble(x = c("08-05-2008", NA)) | ||
| @@ -111,15 +143,6 @@ test_that("strptime", { | ||
| ) | ||
| }) | ||
| test_that("errors in strptime", { | ||
| # Error when tz is passed | ||
| x <- Expression$field_ref("x") | ||
| expect_error( | ||
| call_binding("strptime", x, tz = "PDT"), | ||
| "Time zone argument not supported in Arrow" | ||
| ) | ||
| }) | ||
| 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", NA) | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.