-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: add more tests and docs for extraction of date components (#155)
* misc: add more tests for extraction of date components, document those functions * fix
- Loading branch information
1 parent
0cb9fea
commit 517afc7
Showing
4 changed files
with
73 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,22 +1,39 @@ | ||
patrick::with_parameters_test_that( | ||
"extracting date components works", { | ||
"extracting date components works", | ||
{ | ||
for_all( | ||
tests = 20, | ||
date = date_(), | ||
property = function(date) { | ||
date = date_(any_na = TRUE), | ||
datetime = posixct_(any_na = TRUE), | ||
property = function(date, datetime) { | ||
# date ----------------------------------- | ||
test_df <- data.frame(x1 = date) | ||
test <- pl$DataFrame(x1 = date) | ||
|
||
pl_code <- paste0("mutate(test, foo = ", fun, "(date)) |> pull(foo)") | ||
tv_code <- paste0("mutate(test_df, foo = ", fun, "(date)) |> pull(foo)") | ||
pl_code <- paste0("mutate(test, foo = ", fun, "(x1)) |> pull(foo)") | ||
tv_code <- paste0("mutate(test_df, foo = ", fun, "(x1)) |> pull(foo)") | ||
|
||
expect_equal( | ||
eval(parse(text = pl_code)), | ||
eval(parse(text = tv_code)), | ||
eval(parse(text = tv_code)) | ||
) | ||
|
||
# datetime ----------------------------------- | ||
# TODO: this should be removed eventually | ||
if (!fun %in% c("yday", "mday")) { | ||
test_df <- data.frame(x1 = datetime) | ||
test <- pl$DataFrame(x1 = datetime) | ||
|
||
pl_code <- paste0("mutate(test, foo = ", fun, "(x1)) |> pull(foo)") | ||
tv_code <- paste0("mutate(test_df, foo = ", fun, "(x1)) |> pull(foo)") | ||
|
||
expect_equal( | ||
eval(parse(text = pl_code)), | ||
eval(parse(text = tv_code)) | ||
) | ||
} | ||
} | ||
) | ||
}, | ||
fun = c("year", "month", "day", "quarter", "mday", "yday") | ||
) | ||
|
This file contains 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