Skip to content

Commit f87b47e

Browse files
authored
Merge branch 'master' into integer_overflow
2 parents 261a0b9 + 7061a32 commit f87b47e

File tree

15 files changed

+213
-37
lines changed

15 files changed

+213
-37
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Depends:
6262
Imports:
6363
backports,
6464
checkmate,
65+
cli,
6566
data.table,
6667
digest,
6768
lgr,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ if (getRversion() >= "4.3.0") S3method(chooseOpsMethod,CnfAtom)
229229
if (getRversion() >= "4.3.0") S3method(chooseOpsMethod,CnfClause)
230230
if (getRversion() >= "4.3.0") S3method(chooseOpsMethod,CnfFormula)
231231
import(checkmate)
232+
import(cli)
232233
import(data.table)
233234
import(mlr3)
234235
import(mlr3misc)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# mlr3pipelines 0.9.0-9000
22

3-
* Compatibility with new testthat version 3.3.0
3+
* Pretty-printing some info using the `cli` package now.
44
* Fix: Added internal workaround for `PipeOpNMF` attaching `Biobase`, `BiocGenerics`, and `generics` to the search path during training, prediction or when printing its `$state`.
55
* feat: allow dates in datefeatures pipe op and use data.table for date feature generation.
66
* Added support for internal validation tasks to `PipeOpFeatureUnion`.
77
* feat: `PipeOpLearnerCV` can reuse the cross-validation models during prediction by averaging their outputs (`resampling.predict_method = "cv_ensemble"`).
88
* feat: `PipeOpRegrAvg` gets new `se_aggr` and `se_aggr_rho` hyperparameters and now allows various forms of SE aggregation.
99
* Fix: `PipeOpRemoveConstants` now avoids integer overflow when evaluating relative tolerances for near-`integer.max` data.
10+
* Compatibility with new testthat version 3.3.0
1011

1112
# mlr3pipelines 0.9.0
1213

R/Graph.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,25 @@ Graph = R6Class("Graph",
414414
scc = self$edges[, list(sccssors = paste(unique(dst_id), collapse = ",")), by = list(ID = src_id)]
415415
lines = scc[prd[lines, on = "ID"], on = "ID"][, c("ID", "State", "sccssors", "prdcssors")]
416416
lines[is.na(lines)] = ""
417-
catf("Graph with %s PipeOps:", nrow(lines))
417+
cat_cli(cli_h1("Graph with {nrow(lines)} PipeOps:"))
418418
## limit column width ##
419419

420420
outwidth = getOption("width") %??% 80 # output width we want (default 80)
421421
colwidths = map_int(lines, function(x) max(nchar(x), na.rm = TRUE)) # original width of columns
422422
collimit = calculate_collimit(colwidths, outwidth)
423+
423424
opts = options(datatable.prettyprint.char = collimit)
424425
on.exit(options(opts), add = TRUE)
425426
print(lines, row.names = FALSE)
427+
428+
is_sequential = all(table(self$edges$src_id) <= 1) && all(table(self$edges$dst_id) <= 1)
429+
if(is_sequential) {
430+
ppunit = paste0(self$ids(), collapse = " -> ")
431+
pp = paste0(c("<INPUT>", ppunit, "<OUTPUT>"), collapse = " -> ")
432+
} else {
433+
pp = "non-sequential"
434+
}
435+
cat_cli(cli_h3("Pipeline: {.strong {pp}}"))
426436
} else {
427437
cat("Empty Graph.\n")
428438
}

R/GraphLearner.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner,
312312
},
313313
plot = function(html = FALSE, horizontal = FALSE, ...) {
314314
private$.graph$plot(html = html, horizontal = horizontal, ...)
315+
},
316+
print = function() {
317+
super$print(self)
318+
319+
is_sequential = all(table(self$edges$src_id) <= 1) && all(table(self$edges$dst_id) <= 1)
320+
if(is_sequential) {
321+
ppunit = paste0(self$ids(), collapse = " -> ")
322+
pp = paste0(c("<INPUT>", ppunit, "<OUTPUT>"), collapse = " -> ")
323+
} else {
324+
pp = "non-sequential"
325+
}
326+
cat_cli(cli_h3("Pipeline: {.strong {pp}}"))
315327
}
316328
),
317329
active = list(

R/PipeOp.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,23 @@ PipeOp = R6Class("PipeOp",
278278

279279
print = function(...) {
280280
type_table_printout = function(table) {
281-
strings = do.call(sprintf, cbind(fmt = "%s`[%s,%s]", table[, c("name", "train", "predict")]))
282-
strings = strwrap(paste(strings, collapse = ", "), indent = 2, exdent = 2)
283-
if (length(strings) > 6) {
284-
strings = c(strings[1:5], sprintf(" [... (%s lines omitted)]", length(strings) - 5))
281+
print(head(table, 5L), row.names = FALSE, print.keys = FALSE)
282+
if (nrow(table) > 5L) {
283+
catf("[...] (%i rows omitted)", nrow(table) - 5L)
285284
}
286-
gsub("`", " ", paste(strings, collapse = "\n"))
287285
}
288286

289-
catf("PipeOp: <%s> (%strained)", self$id, if (self$is_trained) "" else "not ")
290-
catf("values: <%s>", as_short_string(self$param_set$values))
291-
catf("Input channels <name [train type, predict type]>:\n%s", type_table_printout(self$input))
292-
catf("Output channels <name [train type, predict type]>:\n%s", type_table_printout(self$output))
287+
msg_h = if (self$is_trained) "" else "not "
288+
cat_cli({
289+
cli_h1("PipeOp {.cls {self$id}}: {msg_h}trained")
290+
cli_text("Values: {as_short_string(self$param_set$values)}")
291+
cli_h3("{.strong Input channels:}")
292+
})
293+
type_table_printout(self$input)
294+
cat_cli({
295+
cli_h3("{.strong Output channels:}")
296+
})
297+
type_table_printout(self$output)
293298
},
294299

295300
train = function(input) {

R/PipeOpFixFactors.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,30 @@
4545
#' @section Methods:
4646
#' Only methods inherited from [`PipeOpTaskPreprocSimple`]/[`PipeOpTaskPreproc`]/[`PipeOp`].
4747
#'
48+
#' @examples
49+
#' library("mlr3")
50+
#'
51+
#' # Reduced task with no entries for the installment_rate < 20 is defined
52+
#' task = tsk("german_credit")
53+
#' rows = task$row_ids[task$data()[, installment_rate != "< 20"]]
54+
#' reduced_task = task$clone(deep = TRUE)$filter(rows)
55+
#' levels(reduced_task$data()$installment_rate)
56+
#'
57+
#' # PipeOp is trained on the reduced task
58+
#' po = po("fixfactors")
59+
#' processed_task = preproc(reduced_task, po)
60+
#' levels(processed_task$data()$installment_rate)
61+
#' summary(processed_task$data()$installment_rate)
62+
#'
63+
#' predicted_task = preproc(task, po, predict = TRUE)
64+
#'
65+
#' # Predictions are made on the task without any missing data
66+
#' levels(predicted_task$data()$installment_rate)
67+
#' summary(predicted_task$data()$installment_rate)
4868
#' @family PipeOps
4969
#' @template seealso_pipeopslist
5070
#' @include PipeOpTaskPreproc.R
5171
#' @export
52-
#' @examples
53-
#' library("mlr3")
5472
PipeOpFixFactors = R6Class("PipeOpFixFactors",
5573
inherit = PipeOpTaskPreprocSimple,
5674
public = list(

R/PipeOpTrafo.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,37 @@ PipeOpTargetTrafo = R6Class("PipeOpTargetTrafo",
221221
#' @section Methods:
222222
#' Only methods inherited from [`PipeOp`].
223223
#'
224+
#' @examplesIf requireNamespace("rpart")
225+
#' library(mlr3)
226+
#' task = tsk("boston_housing")
227+
#' po = PipeOpTargetMutate$new("logtrafo", param_vals = list(
228+
#' trafo = function(x) log(x, base = 2),
229+
#' inverter = function(x) list(response = 2 ^ x$response))
230+
#' )
231+
#' # Note that this example is ill-equipped to work with
232+
#' # `predict_type == "se"` predictions.
233+
#'
234+
#' po$train(list(task))
235+
#' po$predict(list(task))
236+
#'
237+
#' g = Graph$new()
238+
#' g$add_pipeop(po)
239+
#' g$add_pipeop(LearnerRegrRpart$new())
240+
#' g$add_pipeop(PipeOpTargetInvert$new())
241+
#' g$add_edge(src_id = "logtrafo", dst_id = "targetinvert",
242+
#' src_channel = 1, dst_channel = 1)
243+
#' g$add_edge(src_id = "logtrafo", dst_id = "regr.rpart",
244+
#' src_channel = 2, dst_channel = 1)
245+
#' g$add_edge(src_id = "regr.rpart", dst_id = "targetinvert",
246+
#' src_channel = 1, dst_channel = 2)
247+
#'
248+
#' g$train(task)
249+
#' g$predict(task)
250+
#'
251+
#' #syntactic sugar using ppl():
252+
#' tt = ppl("targettrafo", graph = PipeOpLearner$new(LearnerRegrRpart$new()))
253+
#' tt$param_set$values$targetmutate.trafo = function(x) log(x, base = 2)
254+
#' tt$param_set$values$targetmutate.inverter = function(x) list(response = 2 ^ x$response)
224255
#' @family PipeOps
225256
#' @template seealso_pipeopslist
226257
#' @include PipeOp.R

R/multiplicity.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ print.Multiplicity = function(x, ...) {
5656
if (!length(x)) {
5757
cat("Empty Multiplicity.\n")
5858
} else {
59-
cat("Multiplicity:\n")
59+
cli_h2("Multiplicity:")
6060
print(unclass(x), ...)
6161
}
6262
}

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#' @import data.table
22
#' @import checkmate
3+
#' @import cli
34
#' @import mlr3
45
#' @import paradox
56
#' @import mlr3misc

0 commit comments

Comments
 (0)