Skip to content

Commit

Permalink
Merge pull request #24 from UchidaMizuki/fix-rbind-#23
Browse files Browse the repository at this point in the history
Fix rbind() and add tests (#23)
  • Loading branch information
UchidaMizuki authored Aug 24, 2024
2 parents 7388c04 + fe266b2 commit ce45e39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/dim_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ union_dim_names <- function(x) {
}

intersect_dim_names <- function(x) {
purrr::modify(purrr::list_transpose(x),
purrr::modify(purrr::list_transpose(x, simplify = FALSE),
function(x) {
purrr::reduce(x, set_intersect)
})
}

diff_dim_names <- function(x) {
purrr::modify(purrr::list_transpose(x),
purrr::modify(purrr::list_transpose(x, simplify = FALSE),
function(x) {
purrr::reduce(x, set_diff)
})
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test-rbind.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,30 @@ test_that("rbind.ddf_col() and rbind.tbl_ddf() work", {
filter(axis1 %in% dimnames(ddf_col2)[["axis1"]],
axis2 %in% dimnames(ddf_col2)[["axis2"]]),
ddf_col2)

# works when the number of key rows is 1 (#23)
data_1 <- tidyr::expand_grid(key = tibble::tibble(col_1 = 1,
col_2 = 1)) |>
tibble::add_column(value = 1) |>
dibble_by("key")

data_2 <- tidyr::expand_grid(key = tibble::tibble(col_1 = 2:3,
col_2 = 2:3)) |>
tibble::add_column(value = 2) |>
dibble_by("key")

data_3 <- tidyr::expand_grid(key = tibble::tibble(col_1 = 2,
col_2 = 2)) |>
tibble::add_column(value = 2) |>
dibble_by("key")

data_4 <- tidyr::expand_grid(key = tibble::tibble(col_1 = 2,
col_2 = 2),
key_2 = tibble::tibble(col_1 = 2)) |>
tibble::add_column(value = 2) |>
dibble_by("key", "key_2")

expect_no_error(broadcast(rbind(data_1, data_2), "key"))
expect_no_error(broadcast(rbind(data_1, data_3), "key"))
expect_no_error(broadcast(rbind(data_1, data_4), c("key", "key_2")))
})

0 comments on commit ce45e39

Please sign in to comment.