Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for non-package models #1230

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -301,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)
Expand All @@ -311,7 +313,7 @@ names0 <- function(num, prefix = "x", call = rlang::caller_env()) {
ind <- gsub(" ", "0", ind)
paste0(prefix, ind)
}

# nocov end

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -602,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
Expand Down
4 changes: 2 additions & 2 deletions man/dot-get_prediction_column_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions parsnip.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: e5169c4e-5aba-443d-938b-8765efc1d040

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-decision_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
Expand Down
41 changes: 41 additions & 0 deletions tests/testthat/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,44 @@ test_that('obtaining prediction columns', {
)

})


# ------------------------------------------------------------------------------

# https://github.com/tidymodels/parsnip/issues/1229
test_that('register local models', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR will follow

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"))
})

Loading