Skip to content

Commit

Permalink
Make test for categorical data deterministic. (#8080)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jul 15, 2022
1 parent dae7a41 commit 647d384
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/python-gpu/test_gpu_updaters.py
Expand Up @@ -87,6 +87,7 @@ def test_categorical_ohe(self, rows, cols, rounds, cats):
def test_categorical_missing(self, rows, cols, cats):
self.cputest.run_categorical_missing(rows, cols, cats, "gpu_hist")

@pytest.mark.skipif(**tm.no_pandas())
def test_max_cat(self) -> None:
self.cputest.run_max_cat("gpu_hist")

Expand Down
6 changes: 5 additions & 1 deletion tests/python/test_updaters.py
Expand Up @@ -205,10 +205,13 @@ def test_invalid_category(self) -> None:
def run_max_cat(self, tree_method: str) -> None:
"""Test data with size smaller than number of categories."""
import pandas as pd

rng = np.random.default_rng(0)
n_cat = 100
n = 5

X = pd.Series(
["".join(choice(ascii_lowercase) for i in range(3)) for i in range(n_cat)],
["".join(rng.choice(list(ascii_lowercase), size=3)) for i in range(n_cat)],
dtype="category",
)[:n].to_frame()

Expand All @@ -222,6 +225,7 @@ def run_max_cat(self, tree_method: str) -> None:
assert tm.non_increasing(reg.evals_result()["validation_0"]["rmse"])

@pytest.mark.parametrize("tree_method", ["hist", "approx"])
@pytest.mark.skipif(**tm.no_pandas())
def test_max_cat(self, tree_method) -> None:
self.run_max_cat(tree_method)

Expand Down

0 comments on commit 647d384

Please sign in to comment.