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