Skip to content

Commit

Permalink
Merge pull request #76 from duckdblabs/f-75-log
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Nov 12, 2023
2 parents 2971498 + ce678d7 commit 1c12f30
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/relational-duckdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ duckplyr_macros <- c(
"is.na" = "(x) AS (x IS NULL)",
"n" = "() AS CAST(COUNT(*) AS int32)",
#
"log10" = "(x) AS log(x)",
"log" = "(x) AS ln(x)",
"log10" = "(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE log(x) END",
"log" = "(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE ln(x) END",
# TPCH

# https://github.com/duckdb/duckdb/discussions/8599
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/test-as_duckplyr_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,34 @@ test_that("as_duckplyr_df() and mutate(c = 0, d = 0, e = c / d)", {
expect_equal(pre, post)
})


test_that("as_duckplyr_df() and mutate(c = 0, d = -1, e = log(c), f = log(d))", {
# Data
test_df <- data.frame(a = 1:6 + 0, b = 2, g = rep(1:3, 1:3))

# Run
pre <- test_df %>% as_duckplyr_df() %>% mutate(c = 0, d = -1, e = log(c), f = log(d))
# FIXME: This is overwritten by autogeneration but necessary, find better solution
post <- test_df %>% mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log(d))) %>% as_duckplyr_df()

# Compare
expect_equal(pre, post)
})


test_that("as_duckplyr_df() and mutate(c = 0, d = -1, e = log(c), f = log10(d))", {
# Data
test_df <- data.frame(a = 1:6 + 0, b = 2, g = rep(1:3, 1:3))

# Run
pre <- test_df %>% as_duckplyr_df() %>% mutate(c = 0, d = -1, e = log(c), f = log10(d))
# FIXME: This is overwritten by autogeneration but necessary, find better solution
post <- test_df %>% mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log10(d))) %>% as_duckplyr_df()

# Compare
expect_equal(pre, post)
})

test_that("as_duckplyr_df() and nest_by()", {
withr::local_envvar(DUCKPLYR_FORCE = "FALSE")

Expand Down
4 changes: 4 additions & 0 deletions tools/00-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,10 @@ test_extra_arg_map <- list(
# Division by zero
"c = 0, d = 0, e = c / d",

# Negative log
"c = 0, d = -1, e = log(c), f = log(d)",
"c = 0, d = -1, e = log(c), f = log10(d)",

NULL
),
nest_join = "join_by(a)",
Expand Down

0 comments on commit 1c12f30

Please sign in to comment.