Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ S3method(grid_latin_hypercube,parameters)
S3method(grid_max_entropy,list)
S3method(grid_max_entropy,param)
S3method(grid_max_entropy,parameters)
S3method(grid_random,default)
S3method(grid_random,list)
S3method(grid_random,param)
S3method(grid_random,parameters)
S3method(grid_regular,default)
S3method(grid_regular,list)
S3method(grid_regular,param)
S3method(grid_regular,parameters)
S3method(grid_space_filling,default)
S3method(grid_space_filling,list)
S3method(grid_space_filling,param)
S3method(grid_space_filling,parameters)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

* Parameters were added for the `tab_pfn` model: `num_estimators()`, `softmax_temperature()`, `balance_probabilities()`, `average_before_softmax()`, and `training_set_limit()`.

* `parameters()` and the `grid_*()` functions give more information in the error message when non-parameter objects are passed in (#437).
* `parameters()` and the `grid_*()` functions give more information in the error message when non-parameter objects are passed in (#437, #438).


# dials 1.4.2
Expand Down
36 changes: 36 additions & 0 deletions R/grids.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ grid_regular <- function(x, ..., levels = 3, original = TRUE, filter = NULL) {
UseMethod("grid_regular")
}

#' @export
#' @rdname grid_regular
grid_regular.default <- function(
x,
...,
levels = 3,
original = TRUE,
filter = NULL
) {
if (missing(x)) {
cli::cli_abort("At least one parameter object is required.")
}
cli::cli_abort(
"{.arg x} must be a {.cls param} object, list, or {.cls parameters} object,
not {.obj_type_friendly {x}}."
)
}

#' @export
#' @rdname grid_regular
grid_regular.parameters <- function(
Expand Down Expand Up @@ -239,6 +257,24 @@ grid_random <- function(x, ..., size = 5, original = TRUE, filter = NULL) {
UseMethod("grid_random")
}

#' @export
#' @rdname grid_regular
grid_random.default <- function(
x,
...,
size = 5,
original = TRUE,
filter = NULL
) {
if (missing(x)) {
cli::cli_abort("At least one parameter object is required.")
}
cli::cli_abort(
"{.arg x} must be a {.cls param} object, list, or {.cls parameters} object,
not {.obj_type_friendly {x}}."
)
}

#' @export
#' @rdname grid_regular
grid_random.parameters <- function(
Expand Down
18 changes: 18 additions & 0 deletions R/space_filling.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ grid_space_filling <- function(
UseMethod("grid_space_filling")
}

#' @export
#' @rdname grid_space_filling
grid_space_filling.default <- function(
x,
...,
size = 5,
type = "any",
original = TRUE
) {
if (missing(x)) {
cli::cli_abort("At least one parameter object is required.")
}
cli::cli_abort(
"{.arg x} must be a {.cls param} object, list, or {.cls parameters} object,
not {.obj_type_friendly {x}}."
)
}

#' @export
#' @rdname grid_space_filling
grid_space_filling.parameters <- function(
Expand Down
6 changes: 6 additions & 0 deletions man/grid_regular.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/grid_space_filling.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions tests/testthat/_snaps/grids.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@
Code
grid_random()
Condition
Error in `UseMethod()`:
! no applicable method for 'grid_random' applied to an object of class "NULL"
Error in `grid_random()`:
! At least one parameter object is required.

---

Code
grid_random("not a param")
Condition
Error in `grid_random()`:
! `x` must be a <param> object, list, or <parameters> object, not a string.

---

Expand Down Expand Up @@ -250,8 +258,16 @@
Code
grid_regular()
Condition
Error in `UseMethod()`:
! no applicable method for 'grid_regular' applied to an object of class "NULL"
Error in `grid_regular()`:
! At least one parameter object is required.

---

Code
grid_regular("not a param")
Condition
Error in `grid_regular()`:
! `x` must be a <param> object, list, or <parameters> object, not a string.

---

Expand Down
12 changes: 10 additions & 2 deletions tests/testthat/_snaps/space_filling.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@
Code
grid_space_filling()
Condition
Error in `UseMethod()`:
! no applicable method for 'grid_space_filling' applied to an object of class "NULL"
Error in `grid_space_filling()`:
! At least one parameter object is required.

---

Code
grid_space_filling("not a param")
Condition
Error in `grid_space_filling()`:
! `x` must be a <param> object, list, or <parameters> object, not a string.

---

Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-grids.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ test_that("grid_random validates inputs", {
})

test_that("grid_random() errors with non-param inputs", {
# no input at all
# default method
expect_snapshot(error = TRUE, grid_random())
expect_snapshot(error = TRUE, grid_random("not a param"))

# param method
expect_snapshot(error = TRUE, grid_random(penalty(), "min_n"))
Expand Down Expand Up @@ -157,8 +158,9 @@ test_that("grid_regular validates inputs", {
})

test_that("grid_regular() errors with non-param inputs", {
# no input at all
# default method
expect_snapshot(error = TRUE, grid_regular())
expect_snapshot(error = TRUE, grid_regular("not a param"))

# param method
expect_snapshot(error = TRUE, grid_regular(penalty(), "min_n"))
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-space_filling.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ test_that("grid_space_filling validates inputs", {
})

test_that("grid_space_filling() errors with non-param inputs", {
# no input at all
# default method
expect_snapshot(error = TRUE, grid_space_filling())
expect_snapshot(error = TRUE, grid_space_filling("not a param"))

# param method
expect_snapshot(error = TRUE, grid_space_filling(penalty(), "min_n"))
Expand Down
Loading