Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test "Good names for dummies with reocurring patterns" fails sometimes #1345

Open
MichaelChirico opened this issue Jul 25, 2023 · 0 comments

Comments

@MichaelChirico
Copy link

Our CI sees the caret suite fail occasionally. I think the test needs to set a seed, or otherwise the code needs to be designed to be robust to random input (at a glance, I am guessing the former).

test_that("Good names for dummies with reocurring patterns", {
data = data.frame(
matrix(
rep(
as.factor(sample.int(15, size = 100, replace = TRUE, prob = rep(1 / 15, 15))
),
15
),
ncol = 15
),
stringsAsFactors = TRUE
)
essai_dummyVars = caret::dummyVars(stats::as.formula(paste0("~ ", colnames(data), collapse = "+")), data)
exp_names_lvls <- apply(expand.grid(paste0("X",1:15), paste0(".",1:15)), 1, paste, collapse="")
res_names_lvls <- colnames(predict(essai_dummyVars, data))
expect_true(all(exp_names_lvls %in% res_names_lvls))
})

replicate(1e4, {
test_that("Good names for dummies with reocurring patterns", {
  data = data.frame(
    matrix(
      rep(
        as.factor(sample.int(15, size = 100, replace = TRUE, prob = rep(1 / 15, 15))
        ),
        15
      ),
      ncol = 15
    ),
    stringsAsFactors = TRUE
  )
  essai_dummyVars = caret::dummyVars(stats::as.formula(paste0("~ ", colnames(data), collapse = "+")), data)

  exp_names_lvls <- apply(expand.grid(paste0("X",1:15), paste0(".",1:15)), 1, paste, collapse="")
  res_names_lvls <- colnames(predict(essai_dummyVars, data))
  expect_true(all(exp_names_lvls %in% res_names_lvls))
})
})

The failure looks like it happens <1% of the time, but the 1e4 replications I used above seems to trigger the issue consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant