Skip to content

Commit

Permalink
apacheGH-35131: [R] Test failure with dev waldo (apache#35308)
Browse files Browse the repository at this point in the history
This PR fixes the tests failing due to the dev version of the waldo package being more strict comparing NaN and NA_real_ values.  (n.b. our CI doesn't yet use the dev version of waldo, so this PR should be tested locally to verify tests pass).
* Closes: apache#35131

Authored-by: Nic Crane <thisisnic@gmail.com>
Signed-off-by: Nic Crane <thisisnic@gmail.com>
  • Loading branch information
thisisnic authored and rtpsw committed May 16, 2023
1 parent 89bb239 commit 3624e6d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
17 changes: 11 additions & 6 deletions r/tests/testthat/test-compute-sort.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,34 @@ test_that("sort(vector), sort(Array), sort(ChunkedArray) give equivalent results
})

test_that("sort(vector), sort(Array), sort(ChunkedArray) give equivalent results on floats", {

test_vec <- tbl$dbl
# Arrow sorts NA and NaN differently, but it's not important, so eliminate here
test_vec[is.nan(test_vec)] <- NA_real_

compare_expression(
sort(.input, decreasing = TRUE, na.last = TRUE),
tbl$dbl
test_vec
)
compare_expression(
sort(.input, decreasing = FALSE, na.last = TRUE),
tbl$dbl
test_vec
)
compare_expression(
sort(.input, decreasing = TRUE, na.last = NA),
tbl$dbl
test_vec
)
compare_expression(
sort(.input, decreasing = TRUE, na.last = FALSE),
tbl$dbl,
test_vec,
)
compare_expression(
sort(.input, decreasing = FALSE, na.last = NA),
tbl$dbl
test_vec
)
compare_expression(
sort(.input, decreasing = FALSE, na.last = FALSE),
tbl$dbl,
test_vec,
)
})

Expand Down
37 changes: 28 additions & 9 deletions r/tests/testthat/test-dplyr-funcs-conditional.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ test_that("coalesce()", {
y = c(NA_real_, 2.2, 3.3),
z = c(1.1, 2.2, 3.3)
)
compare_dplyr_binding(
.input %>%

# we can't use compare_dplyr_binding here as dplyr silently converts NaN to NA in coalesce()
# see https://github.com/tidyverse/dplyr/issues/6833
expect_identical(
arrow_table(df) %>%
mutate(
cw = coalesce(w),
cz = coalesce(z),
Expand All @@ -387,21 +390,29 @@ test_that("coalesce()", {
cwxyz = coalesce(w, x, y, z)
) %>%
collect(),
df
mutate(
df,
cw = c(NA, NaN, NA),
cz = c(1.1, 2.2, 3.3),
cwx = c(NA, NaN, 3.3),
cwxy = c(NA, 2.2, 3.3),
cwxyz = c(1.1, 2.2, 3.3)
)
)

# NaNs stay NaN and are not converted to NA in the results
# (testing this requires expect_identical())
expect_identical(
df %>% Table$create() %>% mutate(cwx = coalesce(w, x)) %>% collect(),
df %>% mutate(cwx = coalesce(w, x))
df %>% mutate(cwx = c(NA, NaN, 3.3))
)
expect_identical(
df %>% Table$create() %>% transmute(cw = coalesce(w)) %>% collect(),
df %>% transmute(cw = coalesce(w))
df %>% transmute(cw = w)
)
expect_identical(
df %>% Table$create() %>% transmute(cn = coalesce(NaN)) %>% collect(),
df %>% transmute(cn = coalesce(NaN))
df %>% transmute(cn = NaN)
)
# singles stay single
expect_equal(
Expand All @@ -418,8 +429,8 @@ test_that("coalesce()", {
float32()
)
# with R literal values
compare_dplyr_binding(
.input %>%
expect_identical(
arrow_table(df) %>%
mutate(
c1 = coalesce(4.4),
c2 = coalesce(NA_real_),
Expand All @@ -429,7 +440,15 @@ test_that("coalesce()", {
c6 = coalesce(w, x, y, NaN)
) %>%
collect(),
df
mutate(
df,
c1 = 4.4,
c2 = NA_real_,
c3 = NaN,
c4 = c(5.5, 2.2, 3.3),
c5 = c(NA, 2.2, 3.3),
c6 = c(NaN, 2.2, 3.3)
)
)

# no arguments
Expand Down

0 comments on commit 3624e6d

Please sign in to comment.