Skip to content

Commit

Permalink
apply suggestions from review
Browse files Browse the repository at this point in the history
* edits to `validate_has_calibration()`:
     * refer to "The workflow" rather than `caller_arg()`
     * Warn rather than error on unneeded calibration set
     * All arguments on one line in function signature
* comment on expectation re: predictions
* doc tweaks
  • Loading branch information
simonpcouch committed Sep 30, 2024
1 parent 47eda7b commit 0a38a86
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
9 changes: 4 additions & 5 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,18 @@ validate_has_model <- function(x, ..., call = caller_env()) {
invisible(x)
}

validate_has_calibration <- function(x, calibration,
x_arg = caller_arg(x), call = caller_env()) {
validate_has_calibration <- function(x, calibration, call = caller_env()) {
if (.should_inner_split(x) && is.null(calibration)) {
cli::cli_abort(
"{.arg {x_arg}} requires a {.arg calibration} set to train but none
"The workflow requires a {.arg calibration} set to train but none
was supplied.",
call = call
)
}

if (!.should_inner_split(x) && !is.null(calibration)) {
cli::cli_abort(
"{.arg {x_arg}} does not require a {.arg calibration} set to train
cli::cli_warn(
"The workflow does not require a {.arg calibration} set to train
but one was supplied.",
call = call
)
Expand Down
2 changes: 1 addition & 1 deletion R/post-action-tailor.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' preprocessor and model. However, in the case where a postprocessor must be
#' trained as well, allotting all of the available data to the `data` argument
#' to train the preprocessor and model would leave no data
#' left to train the postprocessor with---if that were the case, workflows
#' to train the postprocessor with---if that were the case, workflows
#' would need to `predict()` from the preprocessor and model on the same `data`
#' that they were trained on, with the postprocessor then training on those
#' predictions. Predictions on data that a model was trained on likely follow
Expand Down
2 changes: 1 addition & 1 deletion man/add_tailor.Rd

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

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/fit.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
# fit.workflow confirms compatibility of object and calibration

Code
fit(workflow, mtcars, calibration = mtcars)
res <- fit(workflow, mtcars, calibration = mtcars)
Condition
Error in `fit()`:
! `object` does not require a `calibration` set to train but one was supplied.
Warning in `fit()`:
The workflow does not require a `calibration` set to train but one was supplied.

---

Code
fit(workflow, mtcars)
Condition
Error in `fit()`:
! `object` requires a `calibration` set to train but none was supplied.
! The workflow requires a `calibration` set to train but none was supplied.

# can `predict()` from workflow fit from individual pieces

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ test_that("fit.workflow confirms compatibility of object and calibration", {
workflow <- add_formula(workflow, mpg ~ cyl)
workflow <- add_model(workflow, mod)

expect_snapshot(error = TRUE, {
fit(workflow, mtcars, calibration = mtcars)
})
expect_snapshot(
res <- fit(workflow, mtcars, calibration = mtcars)
)

tailor <- tailor::tailor()
tailor <- tailor::adjust_numeric_calibration(tailor)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-post-action-tailor.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@ test_that("postprocessor fit aligns with manually fitted version (with calibrati
wflow_post_preds <- predict(wf_post_fit, dat_calibration)

expect_equal(wflow_manual_preds[".pred"], wflow_post_preds)

# okay if some predictions are the same, but we wouldn't expect all of them to be
expect_false(all(wflow_simple_preds[".pred"] == wflow_manual_preds[".pred"]))
})

0 comments on commit 0a38a86

Please sign in to comment.