From 6d5e1cdf776f089ebed303e7748cfcb3eaad9db7 Mon Sep 17 00:00:00 2001 From: fis Date: Fri, 15 Jul 2022 13:56:35 +0800 Subject: [PATCH] Make test for categorical data deterministic. --- tests/python-gpu/test_gpu_updaters.py | 1 + tests/python/test_updaters.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/python-gpu/test_gpu_updaters.py b/tests/python-gpu/test_gpu_updaters.py index 043549263e04..95809e2a202d 100644 --- a/tests/python-gpu/test_gpu_updaters.py +++ b/tests/python-gpu/test_gpu_updaters.py @@ -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") diff --git a/tests/python/test_updaters.py b/tests/python/test_updaters.py index 43550c864446..93dfb45c6b45 100644 --- a/tests/python/test_updaters.py +++ b/tests/python/test_updaters.py @@ -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() @@ -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)