Skip to content
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

Date vs string #71

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions duckdb-rfuns-r/tests/testthat/_snaps/spaceship.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# spaceship(<date> <=> <string>)

Code
spaceship_rfuns(as.Date("2024-03-21"), "not a date", "==")
Condition
Error in `map()`:
i In index: 1.
i With name: x.
Caused by error:
! Error evaluating duckdb query: Conversion Error: date field value out of range: "not a date", expected format is (YYYY-MM-DD)

---

Code
spaceship_r(as.Date("2024-03-21"), "not a date", "==")
Condition
Error in `map()`:
i In index: 1.
i With name: ==.
Caused by error in `charToDate()`:
! character string is not in a standard unambiguous format

# spaceship(<time> <=> <string>)

Code
spaceship_rfuns(time, time_chr_gibberish, "==")
Condition
Error in `map()`:
i In index: 1.
i With name: x.
Caused by error:
! Error evaluating duckdb query: Conversion Error: timestamp field value "2024-02-21 14:00:00 gibberish" has a timestamp that is not UTC.
Use the TIMESTAMPTZ type with the ICU extension loaded to handle non-UTC timestamps.

---

Code
spaceship_rfuns(as.POSIXct(strptime("2024-02-21 14:00:00", format = "%Y-%m-%d %H:%M:%S")),
"not a time", "==")
Condition
Error in `map()`:
i In index: 1.
i With name: x.
Caused by error:
! Error evaluating duckdb query: Conversion Error: timestamp field value out of range: "not a time", expected format is (YYYY-MM-DD HH:MM:SS[.US][±HH:MM| ZONE])

---

Code
spaceship_r(as.POSIXct(strptime("2024-02-21 14:00:00", format = "%Y-%m-%d %H:%M:%S")),
"not a time", "==")
Condition
Error in `map()`:
i In index: 1.
i With name: ==.
Caused by error in `as.POSIXlt.character()`:
! character string is not in a standard unambiguous format

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop-eq.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop-gt.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop-gte.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop-lt.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop-lte.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop-neq.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions duckdb-rfuns-r/tests/testthat/gen/relop.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
"<time> <=> <string>"
time <=> "2024-02-21 14:00:00"
time <=> "2024-02-21 13:00:00"
time <=> "2024-02-21 15:00:00"
"2024-02-21 14:00:00" <=> time
"2024-02-21 13:00:00" <=> time
"2024-02-21 15:00:00" <=> time

"<date> <=> <string>"
date <=> "2024-02-21"
date <=> "2024-02-22"
date <=> "2024-02-20"
date <=> "2024-03-21 and then some"
"2024-02-21" <=> date
"2024-02-22" <=> date
"2024-02-20" <=> date
"2024-03-21 and then some" <=> date

"<date> <=> <date>"
date <=> date
date <=> date + 1
Expand Down
23 changes: 21 additions & 2 deletions duckdb-rfuns-r/tests/testthat/helper-expect_spaceship.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
expect_spaceship <- function(x, y) {
expect_equal(

ok_rfuns <- ok_r <- TRUE

rfuns <- tryCatch(
spaceship_rfuns(x, y, keep.data = FALSE),
spaceship_r(x, y, keep.data = FALSE)
error = function(err) {
ok_rfuns <<- FALSE
}
)

r <- tryCatch(
spaceship_r(x, y, keep.data = FALSE),
error = function(err) {
ok_r <<- FALSE
}
)

expect_equal(ok_r, ok_rfuns, info = "<=> should either pass for both or fail for both")

if (ok_r && ok_rfuns) {
expect_equal(rfuns, r)
}

}

3 changes: 2 additions & 1 deletion duckdb-rfuns-r/tests/testthat/helper-gen.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
if (Sys.getenv("CI") == "" ) {

Sys.setlocale("LC_COLLATE", "C")
Sys.setenv("TZ" = "UTC")

# TODO: this should live in the package somewhere
udfs <- c(
Expand All @@ -19,7 +20,7 @@ if (Sys.getenv("CI") == "" ) {

args <- as.list(expr[-1])
env <- new.env()
env$time <- as.POSIXct(strptime('2024-02-21 14:00:00', format = '%Y-%m-%d %H:%M:%S', tz = 'UTC'))
env$time <- as.POSIXct(strptime('2024-02-21 14:00:00', format = '%Y-%m-%d %H:%M:%S'))
env$date <- as.Date("2024-02-21")
env$NA_time <- as.POSIXct(NA)
env$NA_date <- as.Date(NA)
Expand Down
Loading
Loading