Skip to content

Commit

Permalink
colroles tests respect new colroles constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
mb706 committed Sep 6, 2024
1 parent e9210c5 commit 65d1bdc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/testthat/test_pipeop_colroles.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ test_that("PipeOpColRoles - assertion works", {

test_that("PipeOpColRoles - name checking works", {
task = mlr_tasks$get("iris")
op = PipeOpColRoles$new(param_vals = list(new_role = list(Petal.Length = "name", wrong = "feature")))
task$cbind(data.table(rn = sprintf("%03d", 1:150)))
op = PipeOpColRoles$new(param_vals = list(new_role = list(rn = "name", wrong = "feature")))
expect_error(train_pipeop(op, inputs = list(task)), regexp = "subset")
})

Expand All @@ -30,15 +31,16 @@ test_that("PipeOpColRoles - changing the role of a target fails", {

test_that("PipeOpColRoles - functionality works", {
task = mlr_tasks$get("iris")
op = PipeOpColRoles$new(param_vals = list(new_role = list(Petal.Length = c("name", "order"), Petal.Width = character(0))))
task$cbind(data.table(rn = sprintf("%03d", 1:150)))
op = PipeOpColRoles$new(param_vals = list(new_role = list(rn = "name", Petal.Length = "order", Petal.Width = character(0))))
train_out = train_pipeop(op, inputs = list(task))$output
col_roles_actual = train_out$col_roles
col_roles_expected = list(
feature = c("Sepal.Length", "Sepal.Width"), target = "Species", name = "Petal.Length",
feature = c("Sepal.Length", "Sepal.Width"), target = "Species", name = "rn",
order = "Petal.Length", stratum = character(0), group = character(0), weight = character(0))
if ("weights_learner" %in% names(task)) names(col_roles_expected)[names(col_roles_expected) == "weight"] = "weights_learner"
expect_equal(train_out$col_roles[names(col_roles_expected)], col_roles_expected)
expect_equal(train_out$row_names$row_name, task$data(cols = "Petal.Length")[[1L]])
expect_equal(train_out$row_names$row_name, task$data(cols = "rn")[[1L]])
expect_true("Petal.Width" %nin% colnames(train_out$data()))
predict_out = predict_pipeop(op, inputs = list(task))$output
expect_equal(train_out, predict_out)
Expand Down

0 comments on commit 65d1bdc

Please sign in to comment.