-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add missing snapshots - part 1 #1383
Changes from all commits
295df92
3c09c81
df7f23a
07ecf4a
c73025f
8cdb0a7
7f08478
9f6d59f
6a2e410
aeaaa00
7f3f995
e4ee075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,13 @@ prep.step_cut <- function(x, training, info = NULL, ...) { | |
col_names <- recipes_eval_select(x$terms, training, info) | ||
check_type(training[, col_names], types = c("double", "integer")) | ||
|
||
if (!is.numeric(x$breaks)) { | ||
cli::cli_abort( | ||
"{.arg breaks} must be a numeric vector, \\ | ||
EmilHvitfeldt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
not {.obj_type_friendly {breaks}}." | ||
) | ||
} | ||
|
||
all_breaks <- vector("list", length(col_names)) | ||
names(all_breaks) <- col_names | ||
for (col_name in col_names) { | ||
|
@@ -133,19 +140,6 @@ prep.step_cut <- function(x, training, info = NULL, ...) { | |
} | ||
|
||
create_full_breaks <- function(var, breaks) { | ||
if (!is.numeric(var)) { | ||
cli::cli_abort( | ||
"{.arg var} must be a numeric vector, not {.obj_type_friendly {var}}." | ||
) | ||
} | ||
Comment on lines
-136
to
-140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer needed as we do the checking with `check_type() |
||
|
||
if (!is.numeric(breaks)) { | ||
cli::cli_abort( | ||
"{.arg breaks} must be a numeric vector, \\ | ||
not {.obj_type_friendly {breaks}}." | ||
) | ||
} | ||
|
||
if (min(var) < min(breaks)) { | ||
breaks <- c(min(var), breaks) | ||
} | ||
|
@@ -204,12 +198,6 @@ cut_var <- function(var, breaks, include_outside_range) { | |
# the levels when bake.recipe itself is called. Moreover, | ||
# it is cleaner to show it in this way. | ||
adjust_levels_min_max <- function(x) { | ||
if (!is.factor(x)) { | ||
cli::cli_abort( | ||
"{.arg x} must be a factor, not {.obj_type_friendly {x}}.", | ||
.internal = TRUE | ||
) | ||
} | ||
Comment on lines
-207
to
-212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't feel like this was needed, since I checked, and if |
||
levs <- levels(x) | ||
if (length(levs) == 1) { | ||
return(factor(rep("[min,max]", length(x)))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,13 +271,9 @@ bake.step_dummy <- function(object, new_data, ...) { | |
# the original (see the note above) | ||
is_ordered <- attr(levels, "dataClasses") == "ordered" | ||
|
||
if (is.null(levels_values)) { | ||
cli::cli_abort("Factor level values not recorded in {.var col_name}.") | ||
} | ||
|
||
Comment on lines
-274
to
-277
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unreachable as we require that |
||
if (length(levels_values) == 1) { | ||
cli::cli_abort( | ||
"Only one factor level in {.var col_name}: {levels_values}." | ||
"Only one factor level in {.var {col_name}}: {.val {levels_values}}." | ||
) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,8 +142,6 @@ prep.step_dummy_multi_choice <- function(x, training, info = NULL, ...) { | |
col_names <- recipes_eval_select(x$terms, training, info) | ||
check_type(training[, col_names], types = c("nominal", "logical")) | ||
|
||
multi_dummy_check_type(training[, col_names]) | ||
|
||
levels <- purrr::map(training[, col_names], levels) | ||
levels <- vctrs::list_unchop(levels, ptype = character(), name_spec = rlang::zap()) | ||
levels <- levels[!is.na(levels)] | ||
|
@@ -165,23 +163,6 @@ prep.step_dummy_multi_choice <- function(x, training, info = NULL, ...) { | |
) | ||
} | ||
|
||
multi_dummy_check_type <- function(dat, call = rlang::caller_env()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer needed due to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SATISFYING |
||
is_good <- function(x) { | ||
is.factor(x) | is.character(x) | all(is.na(x)) | ||
} | ||
|
||
all_good <- vapply(dat, is_good, logical(1)) | ||
if (!all(all_good)) { | ||
offenders <- names(dat)[!all_good] | ||
cli::cli_abort(c( | ||
"x" = "All columns selected for the step should be \\ | ||
factor, character, or NA. The following were not:", | ||
"*" = "{.var {offenders}}." | ||
), call = call) | ||
} | ||
invisible(all_good) | ||
} | ||
|
||
#' @export | ||
bake.step_dummy_multi_choice <- function(object, new_data, ...) { | ||
col_names <- object$input | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ step_impute_knn <- | |
if (length(options) > 0) { | ||
if (any(!(opt_nms %in% c("eps", "nthread")))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm planning to add a helper function for this as we pass through additional arguments in a list a few places |
||
cli::cli_abort( | ||
"Valid values for {.arg options} are {.val eps}, and {.val nthread}." | ||
"Valid values for {.arg options} are {.val eps} and {.val nthread}." | ||
) | ||
} | ||
if (all(opt_nms != "nthread")) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,14 +113,8 @@ trim <- function(x, trim) { | |
# Adapted from mean.default | ||
x <- sort(x, na.last = TRUE) | ||
na_ind <- is.na(x) | ||
if (!is.numeric(trim) || length(trim) != 1L) { | ||
cli::cli_abort("{.arg trim} must be numeric of length one.") | ||
} | ||
Comment on lines
-116
to
-118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically unreachable, since there is a |
||
n <- length(x[!na_ind]) | ||
if (trim > 0 && n) { | ||
if (is.complex(x)) { | ||
cli::cli_abort("Trimmed means are not defined for complex data.") | ||
} | ||
Comment on lines
-121
to
-123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't be reached since |
||
if (trim >= 0.5) | ||
return(stats::median(x[!na_ind], na.rm = FALSE)) | ||
lo <- floor(n * trim) + 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,8 @@ prep.step_interact <- function(x, training, info = NULL, ...) { | |
) | ||
if (!is_formula(tmp_terms)) { | ||
cli::cli_abort( | ||
"{.arg terms} must be a formula. Not {.obj_type_friendly {term}}." | ||
"{.arg terms} must be a formula, not {.obj_type_friendly {term}}.", | ||
.internal = TRUE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have in a couple of places added |
||
) | ||
} | ||
|
||
|
@@ -209,7 +210,7 @@ prep.step_interact <- function(x, training, info = NULL, ...) { | |
vars <- | ||
unique(unlist(lapply(make_new_formula(int_terms), all.vars))) | ||
var_check <- info[info$variable %in% vars, ] | ||
if (any(var_check$type == "nominal")) { | ||
if (any(vapply(var_check$type, function(x) "nominal" %in% x, logical(1)))) { | ||
cli::cli_warn( | ||
"Categorical variables used in {.fn step_interact} should probably be \\ | ||
avoided; This can lead to differences in dummy variable values that \\ | ||
|
@@ -401,7 +402,10 @@ find_selectors <- function(f) { | |
list() | ||
} else { | ||
# User supplied incorrect input | ||
cli::cli_abort("Don't know how to handle type {typeof(f)}.") | ||
cli::cli_abort( | ||
"Don't know how to handle type {.code {typeof(f)}}.", | ||
.internal = TRUE | ||
) | ||
} | ||
} | ||
|
||
|
@@ -418,7 +422,10 @@ replace_selectors <- function(x, elem, value) { | |
map_pairlist(x, replace_selectors, elem, value) | ||
} else { | ||
# User supplied incorrect input | ||
cli::cli_abort("Don't know how to handle type {typeof(f)}.") | ||
cli::cli_abort( | ||
"Don't know how to handle type {.code {typeof(f)}}.", | ||
.internal = TRUE | ||
) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,7 @@ prep.step_kpca_rbf <- function(x, training, info = NULL, ...) { | |
cli::cli_abort(c( | ||
x = "Failed with error:", | ||
i = as.character(kprc) | ||
)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ought to just set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @simonpcouch do you mind showing an example? i tried for a little bit but not able to get anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can talk more here: #1386 |
||
), .internal = TRUE) | ||
} | ||
} else { | ||
kprc <- NULL | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,19 +84,12 @@ step_relevel_new <- | |
#' @export | ||
prep.step_relevel <- function(x, training, info = NULL, ...) { | ||
col_names <- recipes_eval_select(x$terms, training, info) | ||
check_type(training[, col_names], types = c("string", "factor", "ordered")) | ||
check_type(training[, col_names], types = c("string", "factor")) | ||
|
||
# Get existing levels and their factor type (i.e. ordered) | ||
objects <- lapply(training[, col_names], get_existing_values) | ||
# Check to make sure that no ordered levels are provided | ||
order_check <- map_lgl(objects, attr, "is_ordered") | ||
if (any(order_check)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't needed as we can do it with |
||
offenders <- names(order_check)[order_check] | ||
cli::cli_abort( | ||
"Columns contain ordered factors (which cannot be releveled) \\ | ||
{.val {x$ref_level}}: {offenders}." | ||
) | ||
} | ||
|
||
# Check to make sure that the reference level exists in the factor | ||
ref_check <- map_lgl(objects, function(x, y) !y %in% x, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unreachable because we are already checking for this in
step_count()
in line 83