tidymodels / recipes

Pipeable steps for feature engineering and data preprocessing to prepare for modeling
https://recipes.tidymodels.org
Other
571 stars 113 forks source link

baking `step_discretize()` errors when applied to a single NA. #1350

Open EmilHvitfeldt opened 4 months ago

EmilHvitfeldt commented 4 months ago
library(recipes)

rec <- recipe(~ mpg, data = mtcars) |>
  step_discretize(mpg, min_unique = 4) |>
  prep()

rec |>
  bake(data.frame(mpg = c(NA, 3)))
#> # A tibble: 2 × 1
#>   mpg  
#>   <fct>
#> 1 <NA> 
#> 2 bin1

rec |>
  bake(data.frame(mpg = c(3)))
#> # A tibble: 1 × 1
#>   mpg  
#>   <fct>
#> 1 bin1

rec |>
  bake(data.frame(mpg = c(NA)))
#> Error in cut.default(new_data, object$breaks, labels = labs, include.lowest = TRUE): 'x' must be numeric