Skip to content

Commit

Permalink
Merge pull request #1204 from tidymodels/no-more-fancy-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt authored Sep 28, 2023
2 parents b3173c8 + 474228d commit 9e00c87
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 11 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ importFrom(magrittr,"%>%")
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(purrr,map_dbl)
importFrom(purrr,map_dfr)
importFrom(purrr,map_lgl)
importFrom(stats,as.formula)
importFrom(stats,binomial)
Expand Down
3 changes: 2 additions & 1 deletion R/dummy.R
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ get_dummy_columns <- function(x, one_hot) {
tidy.step_dummy <- function(x, ...) {
if (is_trained(x)) {
if (length(x$levels) > 0) {
res <- purrr::map_dfr(x$levels, get_dummy_columns, x$one_hot, .id = "terms")
res <- purrr::map(x$levels, get_dummy_columns, x$one_hot)
res <- purrr::list_rbind(res, names_to = "terms")
} else {
res <- tibble(terms = character(), columns = character())
}
Expand Down
6 changes: 4 additions & 2 deletions R/dummy_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ bake.step_dummy_extract <- function(object, new_data, ...) {
sort(object$levels[[col_name]]),
object$other
)
indicators <- purrr::map_dfc(indicators, vec_cast, integer())
indicators <- purrr::map(indicators, vec_cast, integer())
indicators <- vctrs::vec_cbind(!!!indicators)

## use backticks for nonstandard factor levels here
used_lvl <- gsub(paste0("^", col_name), "", colnames(indicators))
Expand Down Expand Up @@ -301,7 +302,8 @@ print.step_dummy_extract <-
tidy.step_dummy_extract <- function(x, ...) {
if (is_trained(x)) {
if (length(x$levels) > 0) {
res <- purrr::map_dfr(x$levels, ~ list(columns = .x), FALSE, .id = "terms")
res <- purrr::map(x$levels, ~ tibble(columns = .x), FALSE)
res <- purrr::list_rbind(res, names_to = "terms")
} else {
res <- tibble(terms = character(), columns = character())
}
Expand Down
3 changes: 2 additions & 1 deletion R/filter_missing.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ print.step_filter_missing <-
}

filter_missing_fun <- function(x, threshold, wts) {
x_na <- purrr::map_dfc(x, is.na)
x_na <- purrr::map(x, is.na)
x_na <- vctrs::vec_cbind(!!!x_na)
missing <- averages(x_na, wts = wts)
removal_ind <- which(missing > threshold)
names(x)[removal_ind]
Expand Down
3 changes: 2 additions & 1 deletion R/holiday.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ bake.step_holiday <- function(object, new_data, ...) {
)

names(tmp) <- paste(col_name, names(tmp), sep = "_")
tmp <- purrr::map_dfc(tmp, vec_cast, integer())
tmp <- purrr::map(tmp, vec_cast, integer())
tmp <- vctrs::vec_cbind(!!!tmp)

tmp <- check_name(tmp, new_data, object, names(tmp))
new_data <- vec_cbind(new_data, tmp)
Expand Down
3 changes: 2 additions & 1 deletion R/impute_mean.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ prep.step_impute_mean <- function(x, training, info = NULL, ...) {
wts <- NULL
}

trimmed <- purrr::map_dfc(training[, col_names], trim, x$trim)
trimmed <- purrr::map(training[, col_names], trim, x$trim)
trimmed <- vctrs::vec_cbind(!!!trimmed)

means <- averages(trimmed, wts = wts)
means <- purrr::map2(means, trimmed, cast)
Expand Down
4 changes: 3 additions & 1 deletion R/percentile.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ tidy.step_percentile <- function(x, ...) {
percentile = numeric()
)
} else {
res <- map_dfr(x$ref_dist, format_pctl, .id = "term")
res <- map(x$ref_dist, format_pctl)
res <- purrr::list_rbind(res, names_to = "terms")

}
} else {
term_names <- sel2char(x$terms)
Expand Down
1 change: 0 additions & 1 deletion R/recipes-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
#' @importFrom purrr map
#' @importFrom purrr map_chr
#' @importFrom purrr map_dbl
#' @importFrom purrr map_dfr
#' @importFrom purrr map_lgl
#' @importFrom stats as.formula
#' @importFrom stats binomial
Expand Down
4 changes: 3 additions & 1 deletion R/time.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ get_time_features <- function(dt, feats) {
decimal_day = function(x) hour(x) + (second(x) + minute(x) * 60) / 3600
)

purrr::map_dfc(features[feats], ~.x(dt))
res <- purrr::map(features[feats], ~.x(dt))
res <- vctrs::vec_cbind(!!!res)
res
}


Expand Down
3 changes: 2 additions & 1 deletion R/tunable.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ tunable.recipe <- function(x, ...) {
if (length(x$steps) == 0) {
res <- no_param
} else {
res <- purrr::map_dfr(x$steps, tunable)
res <- purrr::map(x$steps, tunable)
res <- vctrs::vec_rbind(!!!res)
if (nrow(res) > 0) {
res <- res[!is.na(res$name), ]
}
Expand Down

0 comments on commit 9e00c87

Please sign in to comment.