Skip to content

Commit 18949a9

Browse files
committed
restore inferred type
1 parent 4d15497 commit 18949a9

9 files changed

+35
-30
lines changed

R/tailor.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ new_tailor <- function(type, adjustments, columns, ptype, call) {
9090
{.val adjustment}: {bad_adjustment}.", call = call)
9191
}
9292

93+
orderings <- adjustment_orderings(adjustments)
94+
95+
if (type == "unknown") {
96+
type <- infer_type(orderings)
97+
}
98+
9399
# validate adjustment order and check duplicates
94-
validate_order(adjustments, type, call)
100+
validate_order(orderings, type, call)
95101

96102
# check columns
97103
res <- list(
@@ -226,5 +232,5 @@ set_tailor_type <- function(object, y) {
226232
# todo setup eval_time
227233
# todo missing methods:
228234
# todo tune_args
229-
# todo tidy
235+
# todo tidy (this should probably just be `adjustment_orderings()`)
230236
# todo extract_parameter_set_dials

R/utils.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ tailor_adjustment_requires_fit <- function(x) {
8888
isTRUE(x$requires_fit)
8989
}
9090

91+
# an tidy-esque method for adjustment lists, used in validating
92+
# compatibility of adjustments
93+
adjustment_orderings <- function(adjustments) {
94+
tibble::new_tibble(list(
95+
name = purrr::map_chr(adjustments, ~ class(.x)[1]),
96+
input = purrr::map_chr(adjustments, ~ .x$inputs),
97+
output_numeric = purrr::map_lgl(adjustments, ~ grepl("numeric", .x$outputs)),
98+
output_prob = purrr::map_lgl(adjustments, ~ grepl("probability", .x$outputs)),
99+
output_class = purrr::map_lgl(adjustments, ~ grepl("class", .x$outputs)),
100+
output_all = purrr::map_lgl(adjustments, ~ grepl("everything", .x$outputs))
101+
))
102+
}
103+
91104
# ad-hoc checking --------------------------------------------------------------
92105
check_tailor <- function(x, calibration_type = NULL, call = caller_env(), arg = caller_arg(x)) {
93106
if (!is_tailor(x)) {

R/validation-rules.R

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
validate_order <- function(adjustments, type, call = caller_env()) {
2-
orderings <-
3-
tibble::new_tibble(list(
4-
name = purrr::map_chr(adjustments, ~ class(.x)[1]),
5-
input = purrr::map_chr(adjustments, ~ .x$inputs),
6-
output_numeric = purrr::map_lgl(adjustments, ~ grepl("numeric", .x$outputs)),
7-
output_prob = purrr::map_lgl(adjustments, ~ grepl("probability", .x$outputs)),
8-
output_class = purrr::map_lgl(adjustments, ~ grepl("class", .x$outputs)),
9-
output_all = purrr::map_lgl(adjustments, ~ grepl("everything", .x$outputs))
10-
))
11-
12-
if (length(adjustments) < 2) {
1+
validate_order <- function(orderings, type, call = caller_env()) {
2+
if (nrow(orderings) < 2) {
133
return(invisible(orderings))
144
}
155

166
check_incompatible_types(orderings, call)
177

18-
if (type == "unknown") {
19-
type <- infer_type(orderings)
20-
}
21-
228
switch(
239
type,
2410
regression = check_regression_order(orderings, call),

tests/testthat/_snaps/adjust-equivocal-zone.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Message
66
77
-- tailor ----------------------------------------------------------------------
8-
A postprocessor with 1 adjustment:
8+
A binary postprocessor with 1 adjustment:
99
1010
* Add equivocal zone of size 0.1.
1111

@@ -16,7 +16,7 @@
1616
Message
1717
1818
-- tailor ----------------------------------------------------------------------
19-
A postprocessor with 1 adjustment:
19+
A binary postprocessor with 1 adjustment:
2020
2121
* Add equivocal zone of optimized size.
2222

tests/testthat/_snaps/adjust-numeric-calibration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Message
66
77
-- tailor ----------------------------------------------------------------------
8-
A postprocessor with 1 adjustment:
8+
A regression postprocessor with 1 adjustment:
99
1010
* Re-calibrate numeric predictions.
1111

tests/testthat/_snaps/adjust-numeric-range.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Message
66
77
-- tailor ----------------------------------------------------------------------
8-
A postprocessor with 1 adjustment:
8+
A regression postprocessor with 1 adjustment:
99
1010
* Constrain numeric predictions to be between [-Inf, Inf].
1111

@@ -16,7 +16,7 @@
1616
Message
1717
1818
-- tailor ----------------------------------------------------------------------
19-
A postprocessor with 1 adjustment:
19+
A regression postprocessor with 1 adjustment:
2020
2121
* Constrain numeric predictions to be between [?, Inf].
2222

@@ -27,7 +27,7 @@
2727
Message
2828
2929
-- tailor ----------------------------------------------------------------------
30-
A postprocessor with 1 adjustment:
30+
A regression postprocessor with 1 adjustment:
3131
3232
* Constrain numeric predictions to be between [-1, ?].
3333

@@ -38,7 +38,7 @@
3838
Message
3939
4040
-- tailor ----------------------------------------------------------------------
41-
A postprocessor with 1 adjustment:
41+
A regression postprocessor with 1 adjustment:
4242
4343
* Constrain numeric predictions to be between [?, 1].
4444

tests/testthat/_snaps/adjust-probability-calibration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Message
66
77
-- tailor ----------------------------------------------------------------------
8-
A postprocessor with 1 adjustment:
8+
A binary postprocessor with 1 adjustment:
99
1010
* Re-calibrate classification probabilities.
1111

tests/testthat/_snaps/adjust-probability-threshold.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Message
66
77
-- tailor ----------------------------------------------------------------------
8-
A postprocessor with 1 adjustment:
8+
A binary postprocessor with 1 adjustment:
99
1010
* Adjust probability threshold to 0.5.
1111

@@ -16,7 +16,7 @@
1616
Message
1717
1818
-- tailor ----------------------------------------------------------------------
19-
A postprocessor with 1 adjustment:
19+
A binary postprocessor with 1 adjustment:
2020
2121
* Adjust probability threshold to optimized value.
2222

tests/testthat/_snaps/tailor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Message
2424
2525
-- tailor ----------------------------------------------------------------------
26-
A postprocessor with 1 adjustment:
26+
A binary postprocessor with 1 adjustment:
2727
2828
* Adjust probability threshold to 0.2.
2929

@@ -34,7 +34,7 @@
3434
Message
3535
3636
-- tailor ----------------------------------------------------------------------
37-
A postprocessor with 2 adjustments:
37+
A binary postprocessor with 2 adjustments:
3838
3939
* Adjust probability threshold to 0.2.
4040
* Add equivocal zone of size 0.1.

0 commit comments

Comments
 (0)