Skip to content

Commit

Permalink
test.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Nov 28, 2024
1 parent 56c25f2 commit 91d6d22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions R-package/tests/testthat/test_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,19 @@ test_that("xgb.plot.tree works with and without feature names", {
.skip_if_vcd_not_available()
expect_silent(xgb.plot.tree(feature_names = feature.names, model = bst.Tree.unnamed))
expect_silent(xgb.plot.tree(model = bst.Tree))

## Categorical
y <- rnorm(100)
x <- sample(3, size = 100 * 3, replace = TRUE) |> matrix(nrow = 100)
x <- x - 1
dm <- xgb.DMatrix(data = x, label = y)
setinfo(dm, "feature_type", c("c", "c", "c"))
model <- xgb.train(
data = dm,
params = list(tree_method = "hist"),
nrounds = 2
)
expect_silent(xgb.plot.tree(model = model))
})

test_that("xgb.plot.multi.trees works with and without feature names", {
Expand Down
2 changes: 1 addition & 1 deletion python-package/xgboost/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def to_graphviz(
"The `num_trees` parameter is deprecated, use `tree_idx` insetad. ",
FutureWarning,
)
if tree_idx != 0 and tree_idx != num_trees:
if tree_idx not in (0, num_trees):
raise ValueError(
"Both `num_trees` and `tree_idx` are used, prefer `tree_idx` instead."
)
Expand Down

0 comments on commit 91d6d22

Please sign in to comment.