insightsengineering / teal.data

Data model for teal applications
https://insightsengineering.github.io/teal.data/
Other
8 stars 7 forks source link

`c.join_keys` to merge the parents too #191

Closed vedhav closed 10 months ago

vedhav commented 10 months ago

When a join_keys is merged using c.join_keys it's __parents__ attributed is not merged.

jk1 <- join_keys(join_key("a", "b", "ab"))
parents(jk1) <- list("a" = "b")
parents(jk1)
# $a
# [1] "b"
jk2 <- join_keys(join_key("x", "y", "xy"))
parents(jk2) <- list("x" = "y")
parents(jk2)
# $x
# [1] "y"

jk <- c(jk1, jk2)
parents(jk)
# $a
# [1] "b"
averissimo commented 10 months ago

Good catch!!

It was still in time to be fixed on #184

averissimo commented 10 months ago
testthat::test_that("c.join_key_set merges with empty and non-empty parents", {
  jk1 <- join_keys(
    join_key("d1", "d1", "a")
  )

  jk2 <- join_keys(
    join_key("d3", "d3", "c"),
    join_key("d4", "d4", "d"),
    join_key("d4", "d3", "cd")
  )
  parents(jk2) <- list(d3 = "d4")

  expected <- join_keys(
    join_key("d1", "d1", "a"),
    join_key("d3", "d3", "c"),
    join_key("d4", "d4", "d"),
    join_key("d3", "d4", "cd")
  )
  parents(expected) <- list(d3 = "d4")

  testthat::expect_identical(
    c(jk1, jk2),
    expected
  )

  testthat::expect_equal(
    c(jk2, jk1),
    expected
  )
})
#> Test passed 🥳