Skip to content

Commit

Permalink
fix: remove unintended type conversions when using disjoint_union() (
Browse files Browse the repository at this point in the history
  • Loading branch information
aviator-app[bot] committed Jul 2, 2024
2 parents b145abc + 7e01512 commit 19f9c84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ disjoint_union <- function(...) {
noattr <- setdiff(names(attr), names(ea)) # existint and missing
newattr <- setdiff(names(ea), names(attr)) # new
for (a in seq_along(exattr)) {
attr[[exattr[a]]] <- c(attr[[exattr[a]]], ea[[exattr[a]]])
attr[[exattr[a]]] <- vctrs::vec_c(attr[[exattr[a]]], ea[[exattr[a]]])
}
for (a in seq_along(noattr)) {
attr[[noattr[a]]] <- c(attr[[noattr[a]]], rep(NA, ec[i]))
attr[[noattr[a]]] <- vctrs::vec_c(attr[[noattr[a]]], vctrs::unspecified(ec[[i]]))
}
for (a in seq_along(newattr)) {
attr[[newattr[a]]] <- c(rep(NA, cumec[i]), ea[[newattr[a]]])
attr[[newattr[a]]] <- vctrs::vec_c(vctrs::unspecified(cumec[[i]]), ea[[newattr[a]]])
}
}
edge.attributes(res) <- attr
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ test_that("disjoint_union() works", {
)
})

test_that("disjoint_union() does not convert types", {
# https://github.com/igraph/rigraph/issues/761

g1 <- make_graph(~ A - -B)
g2 <- make_graph(~ D - -E)

g1 <- set_edge_attr(g1, "date", value = as.POSIXct(c("2021-01-01 01:01:01")))
g2 <- set_edge_attr(g2, "date", value = as.POSIXct(c("2021-03-03 03:03:03")))

u <- disjoint_union(g1, g2)

expect_s3_class(E(u)$date, c("POSIXct", "POSIXt"))
})

test_that("intersection() works", {

g1 <- make_ring(10)
Expand Down

0 comments on commit 19f9c84

Please sign in to comment.