From 2925cebdca37e43a3f18422c78e05fa88ede7244 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:38:53 -0700 Subject: [PATCH] [CI] Use latest RAPIDS; Pandas 2.0 compatibility fix (#10175) * [CI] Update RAPIDS to latest stable * [CI] Use rapidsai stable channel; fix syntax errors in Dockerfile.gpu * Don't combine astype() with loc() * Work around https://github.com/dmlc/xgboost/issues/10181 * Fix formatting * Fix test --------- Co-authored-by: hcho3 Co-authored-by: Hyunsu Cho --- python-package/xgboost/data.py | 12 +++++++++++- python-package/xgboost/testing/__init__.py | 4 ++-- tests/buildkite/conftest.sh | 2 +- tests/ci_build/Dockerfile.gpu | 8 ++++---- tests/python-gpu/test_from_cudf.py | 9 --------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/python-package/xgboost/data.py b/python-package/xgboost/data.py index 07a08dc5f..12b576566 100644 --- a/python-package/xgboost/data.py +++ b/python-package/xgboost/data.py @@ -909,9 +909,19 @@ def _transform_cudf_df( enable_categorical: bool, ) -> Tuple[ctypes.c_void_p, list, Optional[FeatureNames], Optional[FeatureTypes]]: try: - from cudf.api.types import is_categorical_dtype + from cudf.api.types import is_bool_dtype, is_categorical_dtype except ImportError: from cudf.utils.dtypes import is_categorical_dtype + from pandas.api.types import is_bool_dtype + + # Work around https://github.com/dmlc/xgboost/issues/10181 + if _is_cudf_ser(data): + if is_bool_dtype(data.dtype): + data = data.astype(np.uint8) + else: + data = data.astype( + {col: np.uint8 for col in data.select_dtypes(include="bool")} + ) if _is_cudf_ser(data): dtypes = [data.dtype] diff --git a/python-package/xgboost/testing/__init__.py b/python-package/xgboost/testing/__init__.py index 409fd0274..f7d9510fa 100644 --- a/python-package/xgboost/testing/__init__.py +++ b/python-package/xgboost/testing/__init__.py @@ -429,8 +429,8 @@ def make_categorical( categories = np.arange(0, n_categories) for col in df.columns: if rng.binomial(1, cat_ratio, size=1)[0] == 1: - df.loc[:, col] = df[col].astype("category") - df.loc[:, col] = df[col].cat.set_categories(categories) + df[col] = df[col].astype("category") + df[col] = df[col].cat.set_categories(categories) if sparsity > 0.0: for i in range(n_features): diff --git a/tests/buildkite/conftest.sh b/tests/buildkite/conftest.sh index 0d051001f..44043910b 100755 --- a/tests/buildkite/conftest.sh +++ b/tests/buildkite/conftest.sh @@ -24,7 +24,7 @@ set -x CUDA_VERSION=11.8.0 NCCL_VERSION=2.16.5-1 -RAPIDS_VERSION=24.02 +RAPIDS_VERSION=24.04 SPARK_VERSION=3.4.0 JDK_VERSION=8 R_VERSION=4.3.2 diff --git a/tests/ci_build/Dockerfile.gpu b/tests/ci_build/Dockerfile.gpu index 698a61e93..255dd9d71 100644 --- a/tests/ci_build/Dockerfile.gpu +++ b/tests/ci_build/Dockerfile.gpu @@ -21,14 +21,14 @@ ENV PATH=/opt/mambaforge/bin:$PATH # Create new Conda environment with cuDF, Dask, and cuPy RUN \ - conda install -c conda-forge mamba && \ - mamba create -n gpu_test -c rapidsai-nightly -c rapidsai -c nvidia -c conda-forge -c defaults \ + export NCCL_SHORT_VER=$(echo "$NCCL_VERSION_ARG" | cut -d "-" -f 1) && \ + mamba create -y -n gpu_test -c rapidsai -c nvidia -c conda-forge \ python=3.10 cudf=$RAPIDS_VERSION_ARG* rmm=$RAPIDS_VERSION_ARG* cudatoolkit=$CUDA_VERSION_ARG \ - nccl>=$(cut -d "-" -f 1 << $NCCL_VERSION_ARG) \ + "nccl>=${NCCL_SHORT_VER}" \ dask=2024.1.1 \ dask-cuda=$RAPIDS_VERSION_ARG* dask-cudf=$RAPIDS_VERSION_ARG* cupy \ numpy pytest pytest-timeout scipy scikit-learn pandas matplotlib wheel python-kubernetes urllib3 graphviz hypothesis \ - pyspark>=3.4.0 cloudpickle cuda-python && \ + "pyspark>=3.4.0" cloudpickle cuda-python && \ mamba clean --all && \ conda run --no-capture-output -n gpu_test pip install buildkite-test-collector diff --git a/tests/python-gpu/test_from_cudf.py b/tests/python-gpu/test_from_cudf.py index 8707af0c8..c3a0b7d5f 100644 --- a/tests/python-gpu/test_from_cudf.py +++ b/tests/python-gpu/test_from_cudf.py @@ -71,15 +71,6 @@ def _test_from_cudf(DMatrixT): assert dtrain.num_col() == 1 assert dtrain.num_row() == 5 - # Boolean is not supported. - X_boolean = cudf.DataFrame({"x": cudf.Series([True, False])}) - with pytest.raises(Exception): - dtrain = DMatrixT(X_boolean) - - y_boolean = cudf.DataFrame({"x": cudf.Series([True, False, True, True, True])}) - with pytest.raises(Exception): - dtrain = DMatrixT(X_boolean, label=y_boolean) - def _test_cudf_training(DMatrixT): import pandas as pd