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

Avoid map2() when wts aren't used #1052

Merged
merged 2 commits into from
Oct 28, 2022

Conversation

DavisVaughan
Copy link
Member

This is a small bug exposed by purrr 1.0.0 (the dev version). If you install the dev version of purrr and run the tests, then some of the step_dummy_extract() ones break because purrr now applies tidyverse recycling rules to its inputs in map2() and pmap(). The error looks like:

> rlang::last_trace()
<error/vctrs_error_incompatible_size>
Error in `purrr::map2()` at recipes/R/extract.R:173:6:
! Can't recycle `.x` (size 4) to match `.y` (size 0).
---
Backtrace:

 1. ├─recipes::prep(dummy)
 2. └─recipes:::prep.recipe(dummy) at recipes/R/recipe.R:278:2
 3.   ├─recipes::prep(x$steps[[i]], training = training, info = x$term_info) at recipes/R/recipe.R:434:8
 4.   └─recipes:::prep.step_dummy_extract(...) at recipes/R/recipe.R:278:2
 5.     └─purrr::map2(lvls, as.double(wts), ~rep(.y, length(.x))) at recipes/R/extract.R:173:6
Run rlang::last_trace(drop = FALSE) to see 6 hidden frames.

It would be great if we could get a small recipes release out to make it easier on purrr, otherwise we are going to be forced to do a release when purrr 1.0.0 eventually goes out.

The problem happens when wts aren't used, i.e. wts = NULL. Then as.double(wts) returns double(), which isn't tidyverse recyclable against lvls, which is typically length >1.

Otherwise `wts` are `NULL`, so `as.double(wts)` returns `double()`, which isn't tidyverse recyclable against `lvls`, which is likely length >1.
Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

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

Looks good. Clean small fix

@DavisVaughan
Copy link
Member Author

DavisVaughan commented Oct 28, 2022

@EmilHvitfeldt I'll let you or Max merge as you see fit

@EmilHvitfeldt EmilHvitfeldt merged commit 5189798 into tidymodels:main Oct 28, 2022
@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2022
@DavisVaughan DavisVaughan deleted the fix/0-length-recycling branch December 15, 2022 16:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants