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

Better warn on unseed levels #1326

Merged
merged 8 commits into from
May 30, 2024
Merged

Conversation

EmilHvitfeldt
Copy link
Member

To close #450

library(recipes)

data <- data.frame(a = c(LETTERS, NA))

aaa <- recipe(~ a, data = data) %>%
  step_dummy(a) %>%
  prep()
#> Warning: ! There are new levels in `a`: NA.
#> ℹ Consider using `recipes::step_unknown()` before `step_dummy()` to handle
#>   missing values.

data_train <- tibble(x = c("a", "b"))
data_test <- tibble(x = "c")

rec_spec <- recipe(~., data = data_train) %>%
  step_dummy(x) %>%
  prep()

aaa <- rec_spec %>%
  bake(data_test)
#> Warning: ! There are new levels in `x`: "c".
#> ℹ Consider using `recipes::step_novel()` before `step_dummy()` to handle unseen
#>   values.

@EmilHvitfeldt EmilHvitfeldt requested a review from simonpcouch May 30, 2024 05:22
Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

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

This is awesome. Knocking out all sorts of QOL improvements. :)

tests/testthat/_snaps/dummy.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
EmilHvitfeldt and others added 2 commits May 30, 2024 11:11
Co-authored-by: Simon P. Couch <simonpatrickcouch@gmail.com>
@EmilHvitfeldt
Copy link
Member Author

the new snapshots looks worse, but they print neater!

Screenshot 2024-05-30 at 11 33 15 AM

@EmilHvitfeldt EmilHvitfeldt merged commit aeff283 into main May 30, 2024
9 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the better-warn-on-unseed-levels branch May 30, 2024 18:45
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 Jun 14, 2024
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.

Uninformative warning message for step_dummy()
2 participants