Skip to content

Commit 3c6d7dc

Browse files
authored
perf: use more lengths() and data.table::setattr() (#1412)
1 parent 28de4c7 commit 3c6d7dc

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

R/PredictionData.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ new_prediction_data = function(li, task_type) {
2828
class(li) = c(fget_key(mlr_reflections$task_types, task_type, "prediction_data", "type"), "PredictionData")
2929

3030
for (i in seq_along(extra_attributes)) {
31-
attr(li, names(extra_attributes)[i]) = extra_attributes[[i]]
31+
setattr(li, names(extra_attributes)[i], extra_attributes[[i]])
3232
}
3333

3434
li

R/PredictionDataClassif.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ check_prediction_data.PredictionDataClassif = function(pdata, train_task, ...) {
5858

5959
if (!is.null(pdata$extra)) {
6060
assert_list(pdata$extra, names = "unique")
61-
len = map_int(pdata$extra, length)
61+
len = lengths(pdata$extra)
6262
if (any(len != n)) {
6363
error_learner_predict("Extra data must have the same length as the number of predictions")
6464
}

R/PredictionDataRegr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ check_prediction_data.PredictionDataRegr = function(pdata, ...) { # nolint
5353

5454
if (!is.null(pdata$extra)) {
5555
assert_list(pdata$extra, names = "unique")
56-
len = map_int(pdata$extra, length)
56+
len = lengths(pdata$extra)
5757
if (any(len != n)) {
5858
error_learner_predict("Extra data must have the same length as the number of predictions")
5959
}

0 commit comments

Comments
 (0)