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

Cannot use bit64::integer64() as logical values #308

Open
nbenn opened this issue Nov 24, 2023 · 3 comments
Open

Cannot use bit64::integer64() as logical values #308

nbenn opened this issue Nov 24, 2023 · 3 comments
Labels

Comments

@nbenn
Copy link
Member

nbenn commented Nov 24, 2023

Trying out a logical_return tweak as function(x) bit64::as.integer64(x), I'm running into an issue where my values get mangled by DBItest such that the later no longer pass expect_identical(). The problem boils down to

values <- c(list(...), .dots)

where ... is empty and .dots is a vector of bit64::integer64() and the following happens

str(c(list(), bit64::as.integer64(c(a = 0, b = 1))))
#> List of 2
#>  $ : num 0
#>  $ : num 4.94e-324
@nbenn nbenn changed the title Cannot use 64::as.integer64 as logical values Cannot use bit64::integer64() as logical values Nov 24, 2023
@krlmlr
Copy link
Member

krlmlr commented Nov 24, 2023

How can I replicate the problem you're seeing? Happy to review a PR too.

@nbenn
Copy link
Member Author

nbenn commented Nov 24, 2023

Running the following code, tests will fail for the reason outlined above.

ctx <- DBItest::make_context(
  RSQLite::SQLite(),
  list(
    dbname = tempfile("DBItest", fileext = ".sqlite"),
    bigint = "integer64"
  ),
  tweaks = DBItest::tweaks(
    logical_return = function(x) bit64::as.integer64(x)
  )
)

DBItest::test_some("data_logical", ctx, FALSE)

@krlmlr
Copy link
Member

krlmlr commented Nov 25, 2023

With output:

ctx <- DBItest::make_context(
  RSQLite::SQLite(),
  list(
    dbname = tempfile("DBItest", fileext = ".sqlite"),
    bigint = "integer64"
  ),
  tweaks = DBItest::tweaks(
    logical_return = function(x) bit64::as.integer64(x)
  )
)

DBItest::test_some("data_logical", ctx, FALSE)
#> ── Failure: DBItest: Result: data_logical ──────────────────────────────────────
#> rows[1L, 1L] not identical to 4.94065645841247e-324.
#> 1/1 mismatches
#> [1] 1 - 4.94e-324 == 1
#> Backtrace:
#>      ▆
#>   1. ├─rlang::exec(test_fun, !!!args) at DBItest/R/run.R:77:11
#>   2. └─DBItest (local) `<fn>`(ctx = `<DBItst_c>`, con = `<SQLtCnnc>`)
#>   3.   ├─testthat::expect_warning(...) at DBItest/R/spec-result-roundtrip.R:29:5
#>   4.   │ └─testthat:::quasi_capture(...)
#>   5.   │   ├─testthat (local) .capture(...)
#>   6.   │   │ └─base::withCallingHandlers(...)
#>   7.   │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>   8.   └─DBItest:::test_select_with_null(...)
#>   9.     └─DBItest:::test_select(..., .add_null = "none") at DBItest/R/spec-result-roundtrip.R:262:3
#>  10.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at DBItest/R/spec-result-roundtrip.R:328:7
#>  11.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
#>  12.       └─testthat::expect_identical(rows[1L, 1L], 4.94065645841247e-324)
#> 
#> ── Failure: DBItest: Result: data_logical ──────────────────────────────────────
#> rows[1L, 2L] not identical to 0.
#> Objects equal but not identical
#> Backtrace:
#>      ▆
#>   1. ├─rlang::exec(test_fun, !!!args) at DBItest/R/run.R:77:11
#>   2. └─DBItest (local) `<fn>`(ctx = `<DBItst_c>`, con = `<SQLtCnnc>`)
#>   3.   ├─testthat::expect_warning(...) at DBItest/R/spec-result-roundtrip.R:29:5
#>   4.   │ └─testthat:::quasi_capture(...)
#>   5.   │   ├─testthat (local) .capture(...)
#>   6.   │   │ └─base::withCallingHandlers(...)
#>   7.   │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>   8.   └─DBItest:::test_select_with_null(...)
#>   9.     └─DBItest:::test_select(..., .add_null = "none") at DBItest/R/spec-result-roundtrip.R:262:3
#>  10.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at DBItest/R/spec-result-roundtrip.R:328:7
#>  11.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
#>  12.       └─testthat::expect_identical(rows[1L, 2L], 0)
#> 
#> ── Failure: DBItest: Result: data_logical ──────────────────────────────────────
#> rows[1L, 1L] not identical to 4.94065645841247e-324.
#> 1/1 mismatches
#> [1] 1 - 4.94e-324 == 1
#> Backtrace:
#>      ▆
#>   1. ├─rlang::exec(test_fun, !!!args) at DBItest/R/run.R:77:11
#>   2. └─DBItest (local) `<fn>`(ctx = `<DBItst_c>`, con = `<SQLtCnnc>`)
#>   3.   ├─testthat::expect_warning(...) at DBItest/R/spec-result-roundtrip.R:29:5
#>   4.   │ └─testthat:::quasi_capture(...)
#>   5.   │   ├─testthat (local) .capture(...)
#>   6.   │   │ └─base::withCallingHandlers(...)
#>   7.   │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>   8.   └─DBItest:::test_select_with_null(...)
#>   9.     └─DBItest:::test_select(..., .add_null = "above") at DBItest/R/spec-result-roundtrip.R:263:3
#>  10.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at DBItest/R/spec-result-roundtrip.R:328:7
#>  11.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
#>  12.       └─testthat::expect_identical(rows[1L, 1L], 4.94065645841247e-324)
#> 
#> ── Failure: DBItest: Result: data_logical ──────────────────────────────────────
#> rows[1L, 2L] not identical to 0.
#> Objects equal but not identical
#> Backtrace:
#>      ▆
#>   1. ├─rlang::exec(test_fun, !!!args) at DBItest/R/run.R:77:11
#>   2. └─DBItest (local) `<fn>`(ctx = `<DBItst_c>`, con = `<SQLtCnnc>`)
#>   3.   ├─testthat::expect_warning(...) at DBItest/R/spec-result-roundtrip.R:29:5
#>   4.   │ └─testthat:::quasi_capture(...)
#>   5.   │   ├─testthat (local) .capture(...)
#>   6.   │   │ └─base::withCallingHandlers(...)
#>   7.   │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>   8.   └─DBItest:::test_select_with_null(...)
#>   9.     └─DBItest:::test_select(..., .add_null = "above") at DBItest/R/spec-result-roundtrip.R:263:3
#>  10.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at DBItest/R/spec-result-roundtrip.R:328:7
#>  11.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
#>  12.       └─testthat::expect_identical(rows[1L, 2L], 0)
#> 
#> ── Failure: DBItest: Result: data_logical ──────────────────────────────────────
#> rows[1L, 1L] not identical to 4.94065645841247e-324.
#> 1/1 mismatches
#> [1] 1 - 4.94e-324 == 1
#> Backtrace:
#>      ▆
#>   1. ├─rlang::exec(test_fun, !!!args) at DBItest/R/run.R:77:11
#>   2. └─DBItest (local) `<fn>`(ctx = `<DBItst_c>`, con = `<SQLtCnnc>`)
#>   3.   ├─testthat::expect_warning(...) at DBItest/R/spec-result-roundtrip.R:29:5
#>   4.   │ └─testthat:::quasi_capture(...)
#>   5.   │   ├─testthat (local) .capture(...)
#>   6.   │   │ └─base::withCallingHandlers(...)
#>   7.   │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>   8.   └─DBItest:::test_select_with_null(...)
#>   9.     └─DBItest:::test_select(..., .add_null = "below") at DBItest/R/spec-result-roundtrip.R:264:3
#>  10.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at DBItest/R/spec-result-roundtrip.R:328:7
#>  11.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
#>  12.       └─testthat::expect_identical(rows[1L, 1L], 4.94065645841247e-324)
#> 
#> ── Failure: DBItest: Result: data_logical ──────────────────────────────────────
#> rows[1L, 2L] not identical to 0.
#> Objects equal but not identical
#> Backtrace:
#>      ▆
#>   1. ├─rlang::exec(test_fun, !!!args) at DBItest/R/run.R:77:11
#>   2. └─DBItest (local) `<fn>`(ctx = `<DBItst_c>`, con = `<SQLtCnnc>`)
#>   3.   ├─testthat::expect_warning(...) at DBItest/R/spec-result-roundtrip.R:29:5
#>   4.   │ └─testthat:::quasi_capture(...)
#>   5.   │   ├─testthat (local) .capture(...)
#>   6.   │   │ └─base::withCallingHandlers(...)
#>   7.   │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>   8.   └─DBItest:::test_select_with_null(...)
#>   9.     └─DBItest:::test_select(..., .add_null = "below") at DBItest/R/spec-result-roundtrip.R:264:3
#>  10.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at DBItest/R/spec-result-roundtrip.R:328:7
#>  11.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
#>  12.       └─testthat::expect_identical(rows[1L, 2L], 0)
#> Error:
#> ! Test failed
#> Backtrace:
#>      ▆
#>   1. └─DBItest::test_some("data_logical", ctx, FALSE)
#>   2.   └─DBItest::test_all(run_only = test, skip = character(), ctx = ctx) at DBItest/R/test-all.R:56:3
#>   3.     └─DBItest::test_result(skip = skip, run_only = run_only, ctx = ctx) at DBItest/R/test-all.R:29:3
#>   4.       └─DBItest:::run_tests(ctx, spec_result, skip, run_only, test_suite) at DBItest/R/test-result.R:17:3
#>   5.         └─base::vapply(...) at DBItest/R/run.R:32:3
#>   6.           └─DBItest (local) FUN(X[[i]], ...)
#>   7.             └─testthat::test_that(...) at DBItest/R/run.R:42:9
#>   8.               └─withr (local) `<fn>`(`<env>`) at DBItest/R/run.R:42:9
#>   9.                 ├─base::tryCatch(...)
#>  10.                 │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  11.                 │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  12.                 │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>  13.                 └─base::eval(handler$expr, handler$envir)
#>  14.                   └─base::eval(handler$expr, handler$envir)
#>  15.                     └─reporter$stop_if_needed()
#>  16.                       └─rlang::abort("Test failed", call = NULL)

Created on 2023-11-25 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants