Skip to content

Commit

Permalink
Added test for predicting from data with reordered columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzwanenburg committed Oct 11, 2024
1 parent 973008a commit 931d985
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions R/TestDataCreators.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ test_create_small_good_data <- function(outcome_type) {



test_create_reverse_column_order_data <- function(outcome_type) {
# Create good dataset with reversed column order.
data <- test_create_good_data(outcome_type = outcome_type)

# Reverse column order.
column_names <- colnames(data@data)
data.table::setcolorder(x = data@data, neworder = rev(column_names))

return(data)
}



test_create_invariant_good_data <- function(outcome_type) {
# Create good dataset with one invariant feature.

Expand Down
14 changes: 14 additions & 0 deletions R/TestFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ test_all_learners_train_predict_vimp <- function(
for (outcome_type in c("continuous", "binomial", "multinomial", "survival")) {
# Obtain data.
full_data <- test_create_good_data(outcome_type)
full_data_reordered <- test_create_reverse_column_order_data(outcome_type)
full_one_sample_data <- test_create_one_sample_data(outcome_type)
one_feature_data <- test_create_single_feature_data(outcome_type)
one_feature_one_sample_data <- test_create_single_feature_one_sample_data(outcome_type)
Expand Down Expand Up @@ -238,6 +239,19 @@ test_all_learners_train_predict_vimp <- function(
prediction_table_reloaded,
ignore_attr = TRUE
)

# Expect that a dataset with different column order produces the same
# predictions.
prediction_table_reordered <- suppressWarnings(.predict(
model,
data = full_data_reordered
))

testthat::expect_equal(
prediction_table,
prediction_table_reordered,
ignore_attr = TRUE
)
}
)

Expand Down

0 comments on commit 931d985

Please sign in to comment.