Skip to content

Commit 82e4022

Browse files
authored
Merge pull request #737 from mlr-org/feat/keep_results
Minor requirements for mlr3torch
2 parents 2fea863 + 0f9c27f commit 82e4022

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Config/testthat/edition: 3
9393
Config/testthat/parallel: true
9494
NeedsCompilation: no
9595
Roxygen: list(markdown = TRUE, r6 = FALSE)
96-
RoxygenNote: 7.2.3
96+
RoxygenNote: 7.2.3.9000
9797
VignetteBuilder: knitr
9898
Collate:
9999
'Graph.R'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ import(mlr3)
148148
import(mlr3misc)
149149
import(paradox)
150150
importFrom(R6,R6Class)
151+
importFrom(data.table,as.data.table)
151152
importFrom(digest,digest)
152153
importFrom(stats,setNames)
153154
importFrom(utils,bibentry)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# mlr3pipelines 0.5.0-9000
22

3+
* Feature: The `$add_pipeop()` method got an argument `clone` (old behaviour `TRUE` by default)
4+
* Bugfix: `PipeOpFeatureUnion` in some rare cases dropped variables called `"x"`
35
* Compatibility with upcoming paradox release
46

57
# mlr3pipelines 0.5.0-2

R/Graph.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#' * `phash` :: `character(1)` \cr
6060
#' Stores a checksum calculated on the [`Graph`] configuration, which includes all [`PipeOp`] hashes
6161
#' *except* their `$param_set$values`, and a hash of `$edges`.
62-
#' * `keep_results` :: `logical(1)` \cr
62+
#' * `keep_results` :: `logical(1)`\cr
6363
#' Whether to store intermediate results in the [`PipeOp`]'s `$.result` slot, mostly for debugging purposes. Default `FALSE`.
6464
#' * `man` :: `character(1)`\cr
6565
#' Identifying string of the help page that shows with `help()`.
@@ -69,13 +69,14 @@
6969
#' (`logical(1)`) -> `character` \cr
7070
#' Get IDs of all [`PipeOp`]s. This is in order that [`PipeOp`]s were added if
7171
#' `sorted` is `FALSE`, and topologically sorted if `sorted` is `TRUE`.
72-
#' * `add_pipeop(op)` \cr
73-
#' ([`PipeOp`] | [`Learner`][mlr3::Learner] | [`Filter`][mlr3filters::Filter] | `...`) -> `self` \cr
72+
#' * `add_pipeop(op, clone = TRUE)` \cr
73+
#' ([`PipeOp`] | [`Learner`][mlr3::Learner] | [`Filter`][mlr3filters::Filter] | `...`, `logical(1)`) -> `self` \cr
7474
#' Mutates [`Graph`] by adding a [`PipeOp`] to the [`Graph`]. This does not add any edges, so the new [`PipeOp`]
7575
#' will not be connected within the [`Graph`] at first.\cr
7676
#' Instead of supplying a [`PipeOp`] directly, an object that can naturally be converted to a [`PipeOp`] can also
7777
#' be supplied, e.g. a [`Learner`][mlr3::Learner] or a [`Filter`][mlr3filters::Filter]; see [`as_pipeop()`].
78-
#' The argument given as `op` is always cloned; to access a `Graph`'s [`PipeOp`]s by-reference, use `$pipeops`.\cr
78+
#' The argument given as `op` is cloned if `clone` is `TRUE` (default); to access a `Graph`'s [`PipeOp`]s
79+
#' by-reference, use `$pipeops`.\cr
7980
#' Note that `$add_pipeop()` is a relatively low-level operation, it is recommended to build graphs using [`%>>%`].
8081
#' * `add_edge(src_id, dst_id, src_channel = NULL, dst_channel = NULL)` \cr
8182
#' (`character(1)`, `character(1)`,
@@ -181,8 +182,8 @@ Graph = R6Class("Graph",
181182
topo_sort(tmp)$id
182183
},
183184

184-
add_pipeop = function(op) {
185-
op = as_pipeop(op, clone = TRUE)
185+
add_pipeop = function(op, clone = TRUE) {
186+
op = as_pipeop(op, clone = assert_flag(clone))
186187
if (op$id %in% names(self$pipeops)) {
187188
stopf("PipeOp with id '%s' already in Graph", op$id)
188189
}

R/PipeOpFeatureUnion.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ cbind_tasks = function(inputs, assert_targets_equal, inprefix) {
202202
# again done by reference
203203
new_features = unlist(c(list(data.table(x = vector(length = task$nrow))),
204204
map(tail(inputs, -1L), .f = function(y) y$data(ids, cols = y$feature_names))), recursive = FALSE)
205+
names(new_features)[1] = make.unique(rev(names(new_features)))[[length(new_features)]]
205206

206207
# we explicitly have to subset to the unique column names, otherwise task$cbind() complains for data.table backends
207208
new_features = new_features[unique(names(new_features))]

R/assert_graph.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ as_graph = function(x, clone = FALSE) {
3939
}
4040

4141
#' @export
42-
as_graph.default = function(x, clone = FALSE) {
43-
Graph$new()$add_pipeop(x) # add_pipeop always clones and checks automatically for convertability
42+
as_graph.default = function(x, clone = TRUE) {
43+
# different default than other methods for backwards compatibility
44+
# previously $add_pipeop() always cloned its input
45+
Graph$new()$add_pipeop(x, clone = clone)
4446
}
4547

4648
#' @export

man/Graph.Rd

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_pipeop_featureunion.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,18 @@ test_that("featureunion - cbind_tasks - duplicates", {
257257
expect_equal(output$data(cols = "x"), inputs[[1L]]$data(cols = "x"))
258258
expect_equivalent(output$data(cols = c("Species", new_iris_names)), task1$data())
259259
})
260+
261+
test_that("featureunion - does not drop 'x' column", {
262+
task1 = as_task_regr(data.table(
263+
z = 1:10,
264+
y = 1:10
265+
), target = "y")
266+
267+
task2 = as_task_regr(data.table(
268+
x = 1:10,
269+
y = 1:10
270+
), target = "y")
271+
272+
taskout = po("featureunion")$train(list(task1, task2))[[1L]]
273+
expect_permutation(taskout$feature_names, c("x", "z"))
274+
})

0 commit comments

Comments
 (0)