emilyriederer / convo

R package based on "Column Names as Contracts" blog post (https://emilyriederer.netlify.app/post/column-name-contracts/)
https://emilyriederer.github.io/convo/
Other
31 stars 1 forks source link

create_pb_agent() does not match any columns if level > 1 #2

Open petrbouchal opened 3 years ago

petrbouchal commented 3 years ago

Hi Emily,

Excellent idea. I took the package for a spin - mainly to see if it can live with the not-recommended scheme of having the measure in the second level.

That's how I found a minor bug in create_pb_agent(), where no checks are run by {pointblank} if level is set to 2 or more.

Reprex:

library(convo)
library(tibble)
library(pointblank)

dt <- tibble(car_id = numeric(), car_name = character(),
             passenger_cnt = numeric())

cnv <- structure(list(level1 = list(car = NULL, 
                                    passenger = NULL), 
                      level2 = list(id = list(valid = "col_is_numeric()"), 
                                    cnt = list(valid = "col_is_numeric()"), 
                                    name = NULL)), class = c("convo", "list"))

evaluate_convo(cnv, names(dt))
#> Level 1
#> - 
#> Level 2
#> -
cagent <- create_pb_agent(cnv, dt, level = 2)
cagent$validation_set
#> # A tibble: 0 x 29
#> # … with 29 variables: i <int>, step_id <chr>, sha1 <chr>,
#> #   assertion_type <chr>, column <list>, values <list>, na_pass <lgl>,
#> #   preconditions <list>, actions <list>, label <chr>, brief <chr>,
#> #   active <list>, eval_active <lgl>, eval_error <lgl>, eval_warning <lgl>,
#> #   capture_stack <list>, all_passed <lgl>, n <int>, n_passed <int>,
#> #   n_failed <int>, f_passed <dbl>, f_failed <dbl>, warn <lgl>, notify <lgl>,
#> #   stop <lgl>, row_sample <dbl>, tbl_checked <list>, time_processed <dttm>,
#> #   proc_duration_s <dbl>
# interrogate(cagent2) # shows no checks if run in an interactive session

Created on 2021-01-13 by the reprex package (v0.3.0)

Looking at the debug, I think it's caused by a bit of regex. I am aware this is experimental but in case it would be helpful I'd be happy to submit my local fix as a PR.

emilyriederer commented 3 years ago

Thank you so much for taking the time to check out the package and report this issue! Now that you say it, I realize my tests only do cover the level-1 checks and are probably too biased towards my own person workflow. I really appreciate your pointing this out.

If you wouldn't mind submitting your fix as a PR, that would be fantastic! Thanks again!