From 7bba4f14a85a8df15ee70de08f127466efe8627f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Sun, 19 Jan 2025 06:31:04 -0500 Subject: [PATCH 1/7] push back a month --- tests/testthat/test-decision_tree.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-decision_tree.R b/tests/testthat/test-decision_tree.R index 545c14262..faecf59f9 100644 --- a/tests/testthat/test-decision_tree.R +++ b/tests/testthat/test-decision_tree.R @@ -30,7 +30,7 @@ test_that('rpart_train is stop-deprecated when it ought to be (#1044)', { # once this test fails, transition `rpart_train()` to `deprecate_stop()` # and transition this test to fail if `rpart_train()` still exists after a year. - if (Sys.Date() > "2025-01-01") { + if (Sys.Date() > "2025-02-01") { expect_snapshot(error = TRUE, rpart_train(mpg ~ ., mtcars)) } }) From bba92cd4424ea533aeafbd475721aeb06a99deca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Sun, 19 Jan 2025 06:31:26 -0500 Subject: [PATCH 2/7] redoc --- man/dot-get_prediction_column_names.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/dot-get_prediction_column_names.Rd b/man/dot-get_prediction_column_names.Rd index 36fba2c08..e04251623 100644 --- a/man/dot-get_prediction_column_names.Rd +++ b/man/dot-get_prediction_column_names.Rd @@ -7,9 +7,9 @@ .get_prediction_column_names(x, syms = FALSE) } \arguments{ -\item{x}{A fitted model (class \code{"model_fit"}) or a fitted workflow.} +\item{x}{A fitted parsnip model (class \code{"model_fit"}) or a fitted workflow.} -\item{syms}{Should the column names be converted to symbols?} +\item{syms}{Should the column names be converted to symbols? Defaults to \code{FALSE}.} } \value{ A list with elements \code{"estimate"} and \code{"probabilities"}. From 0b97aa0e92e807a74bcf2fdc03dea87573d5e62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Sun, 19 Jan 2025 06:33:47 -0500 Subject: [PATCH 3/7] changes for #1229 --- R/misc.R | 14 +++++++------ parsnip.Rproj | 1 + tests/testthat/test-misc.R | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/R/misc.R b/R/misc.R index 263a9b0f2..18db883d3 100644 --- a/R/misc.R +++ b/R/misc.R @@ -241,13 +241,15 @@ prompt_missing_implementation <- function(spec, #' @keywords internal #' @export show_call <- function(object) { - object$method$fit$args <- - map(object$method$fit$args, convert_arg) + object$method$fit$args <- map(object$method$fit$args, convert_arg) - call2(object$method$fit$func["fun"], - !!!object$method$fit$args, - .ns = object$method$fit$func["pkg"] - ) + fn_info <- as.list(object$method$fit$func) + if (!any(names(fn_info) == "pkg")) { + res <- call2(fn_info$fun, !!!object$method$fit$args) + } else { + res <- call2(fn_info$fun, !!!object$method$fit$args, .ns = fn_info$pkg) + } + res } convert_arg <- function(x) { diff --git a/parsnip.Rproj b/parsnip.Rproj index 30e02be1a..c1a14ad62 100644 --- a/parsnip.Rproj +++ b/parsnip.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: e5169c4e-5aba-443d-938b-8765efc1d040 RestoreWorkspace: No SaveWorkspace: No diff --git a/tests/testthat/test-misc.R b/tests/testthat/test-misc.R index 901c92748..b9566fb0f 100644 --- a/tests/testthat/test-misc.R +++ b/tests/testthat/test-misc.R @@ -299,3 +299,44 @@ test_that('obtaining prediction columns', { ) }) + + +# ------------------------------------------------------------------------------ + +# https://github.com/tidymodels/parsnip/issues/1229 +test_that('register local models', { + set_new_model("my_model") + set_model_mode(model = "my_model", mode = "regression") + set_model_engine( + "my_model", + mode = "regression", + eng = "my_engine" + ) + + my_model <- + function(mode = "regression") { + new_model_spec( + "my_model", + args = list(), + eng_args = NULL, + mode = mode, + method = NULL, + engine = NULL + ) + } + + set_fit( + model = "my_model", + eng = "my_engine", + mode = "regression", + value = list( + interface = "matrix", + protect = c("formula", "data"), + func = c(fun = "my_model_fun"), + defaults = list() + ) + ) + + expect_snapshot(my_model() %>% translate("my_engine")) +}) + From d08671bb07932cfc862e1c9855bd5710f074f0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Sun, 19 Jan 2025 06:34:47 -0500 Subject: [PATCH 4/7] small cleanup --- R/misc.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/misc.R b/R/misc.R index 18db883d3..f02bf9a54 100644 --- a/R/misc.R +++ b/R/misc.R @@ -303,8 +303,8 @@ check_args.default <- function(object, call = rlang::caller_env()) { # ------------------------------------------------------------------------------ -# copied form recipes - +# copied from recipes +# nocov start names0 <- function(num, prefix = "x", call = rlang::caller_env()) { if (num < 1) { cli::cli_abort("{.arg num} should be > 0.", call = call) @@ -313,7 +313,7 @@ names0 <- function(num, prefix = "x", call = rlang::caller_env()) { ind <- gsub(" ", "0", ind) paste0(prefix, ind) } - +# nocov end # ------------------------------------------------------------------------------ @@ -604,7 +604,7 @@ is_cran_check <- function() { } if (inherits(x, "workflow")) { - x <- x %>% extract_fit_parsnip(x) + x <- x %>% hardhat::extract_fit_parsnip(x) } model_spec <- extract_spec_parsnip(x) model_engine <- model_spec$engine From a2de921949813c6886279c9127423e1d5107b566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Sun, 19 Jan 2025 06:39:10 -0500 Subject: [PATCH 5/7] update news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index e35af6bcd..43ceb9b07 100644 --- a/NEWS.md +++ b/NEWS.md @@ -31,6 +31,8 @@ * Fixed bug where some models fit using `fit_xy()` couldn't predict (#1166). +* Fixed bug related to using local (non-package) models (#1229) + ## Breaking Change * For quantile prediction, the `quantile` argument to `predict()` has been deprecate in facor of `quantile_levels`. This does not affect models with mode `"quantile regression"`. From 5ea923d037c9d9b8e4e239cd64266ce28523a5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Sun, 19 Jan 2025 11:28:48 -0500 Subject: [PATCH 6/7] snapshot --- tests/testthat/_snaps/misc.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/_snaps/misc.md b/tests/testthat/_snaps/misc.md index b221b1dde..6e43ec0d7 100644 --- a/tests/testthat/_snaps/misc.md +++ b/tests/testthat/_snaps/misc.md @@ -243,3 +243,15 @@ Error in `.get_prediction_column_names()`: ! Prediction information could not be found for this `linear_reg()` with engine "lm" and mode "Depeche". Does a parsnip extension package need to be loaded? +# register local models + + Code + my_model() %>% translate("my_engine") + Output + my model Model Specification (regression) + + Computational engine: my_engine + + Model fit template: + my_model_fun(formula = missing_arg(), data = missing_arg()) + From 8dc16e0f1903ac14b4240d1393c069313827af28 Mon Sep 17 00:00:00 2001 From: Max Kuhn Date: Wed, 29 Jan 2025 12:16:48 -0500 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Hannah Frick --- tests/testthat/test-decision_tree.R | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/testthat/test-decision_tree.R b/tests/testthat/test-decision_tree.R index faecf59f9..7d32fdf0a 100644 --- a/tests/testthat/test-decision_tree.R +++ b/tests/testthat/test-decision_tree.R @@ -25,16 +25,6 @@ test_that('bad input', { ) }) -test_that('rpart_train is stop-deprecated when it ought to be (#1044)', { - skip_on_cran() - - # once this test fails, transition `rpart_train()` to `deprecate_stop()` - # and transition this test to fail if `rpart_train()` still exists after a year. - if (Sys.Date() > "2025-02-01") { - expect_snapshot(error = TRUE, rpart_train(mpg ~ ., mtcars)) - } -}) - # ------------------------------------------------------------------------------ test_that('argument checks for data dimensions', {