recipes icon indicating copy to clipboard operation
recipes copied to clipboard

Don't silently drop NA levels in strings2factors()

Open EmilHvitfeldt opened this issue 5 months ago • 0 comments

Bug first discovered in https://github.com/tidymodels/recipes/issues/1290.

  • [ ] add tests
  • [ ] add news

Before

library(recipes)

ex_data <- tibble(
  x = factor(c("a",NA,"c"), exclude = NULL)
)

ex_data$x
#> [1] a    <NA> c   
#> Levels: a c <NA>

rec_res <- recipe(~., data = ex_data) |>
  prep() |>
  bake(new_data = NULL)

rec_res$x
#> [1] a    <NA> c   
#> Levels: a c

After

library(recipes)

ex_data <- tibble(
  x = factor(c("a",NA,"c"), exclude = NULL)
)

ex_data$x
#> [1] a    <NA> c   
#> Levels: a c <NA>

rec_res <- recipe(~., data = ex_data) |>
  prep() |>
  bake(new_data = NULL)

rec_res$x
#> [1] a    <NA> c   
#> Levels: a c <NA>

EmilHvitfeldt avatar Mar 19 '24 04:03 EmilHvitfeldt