tidymodels / hardhat

Construct Modeling Packages
https://hardhat.tidymodels.org
Other
101 stars 16 forks source link

Warning Message: The `x` argument of `as_tibble.matrix()` must have column names if `.name_repair` is omitted as of tibble 2.0.0. #136

Closed mdancho84 closed 4 years ago

mdancho84 commented 4 years ago

Getting an odd warning message related to as_tibble.matrix(). This also affects workflows.

The `x` argument of `as_tibble.matrix()` must have column names if `.name_repair` is omitted as of tibble 2.0.0.
Using compatibility `.name_repair`.

I believe it's during the mold() and forge() steps that convert the model matrix to tibble.

Reproducible Example

library(recipes)
library(hardhat)
library(dplyr)
library(lifecycle)

set.seed(123)
data <- tibble(
    date = seq.Date(as.Date("2011-01-01"), by = "month", length.out = 12),
    y    = rnorm(12) + 1:12 
)

recipe_spec <- recipe(y ~ date, data) %>%
    step_date(date, features = "month") %>%
    step_mutate(date_num = as.numeric(date)) %>%
    step_rm(date)

mld <- mold(recipe_spec, data)
#> Warning: The `x` argument of `as_tibble.matrix()` must have column names if `.name_repair` is omitted as of tibble 2.0.0.
#> Using compatibility `.name_repair`.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.

Created on 2020-05-25 by the reprex package (v0.3.0)

Lifecycle Last Warning

I see that the issue is tibble:::as_tibble.matrix(date_values). Likely occurs in the model_frame() function where tibble::as_tibble() is called on a matrix (model.frame).

> lifecycle::last_warnings()
[[1]]
<deprecated>
message: The `x` argument of `as_tibble.matrix()` must have column names if `.name_repair` is omitted as of tibble 2.0.0.
Using compatibility `.name_repair`.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
backtrace:
  1. hardhat::mold(recipe_spec, data)
  2. hardhat:::mold.recipe(recipe_spec, data)
  4. hardhat:::run_mold.recipe_blueprint(blueprint, data)
  5. blueprint$mold$process(blueprint = blueprint, data = data)
  7. recipes:::prep.recipe(blueprint$recipe, training = data, fresh = blueprint$fresh)
  9. recipes:::bake.step_date(x$steps[[i]], new_data = training)
 11. tibble:::as_tibble.matrix(date_values)
DavisVaughan commented 4 years ago

Can you try with dev recipes? I'm pretty sure this was fixed there

mdancho84 commented 4 years ago

Yes! It's fixed in the dev version. Thanks so much Davis.

mdancho84 commented 4 years ago

Hey, I'm actually getting this issue again. I think that the reason it went away was because of the lifecycle package only displaying every 8 hours.

DavisVaughan commented 4 years ago

I can't seem to reproduce this

The backtrace seems to imply that it was coming from here:

  1. recipes:::bake.step_date(x$steps[[i]], new_data = training)

But we fixed this in recipe 0.1.10 which has been on cran for awhile https://github.com/tidymodels/recipes/commit/73f14814b763a2df07ccf59c9b96f7bacfcf0151

Could you please check one more time that this is still an issue? Like, install the cran version of recipes, restart R, then run that code in a reprex. Does it still throw the warning?

mdancho84 commented 4 years ago

Hey Davis, I really apologize for wasting your time on this. I upgraded all of my packages, and the warning is no longer present. I believe this was due to a downgraded package.

-Matt

DavisVaughan commented 4 years ago

Not a problem - glad it is fixed!

github-actions[bot] commented 3 years ago

This issue 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.