From 2674b67ac5181a88d622fd2d917354e556777848 Mon Sep 17 00:00:00 2001 From: Hyunsu Cho Date: Sat, 13 Apr 2024 06:12:28 +0000 Subject: [PATCH] Work around https://github.com/dmlc/xgboost/issues/10181 --- python-package/xgboost/data.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python-package/xgboost/data.py b/python-package/xgboost/data.py index 07a08dc5f0b2..4a5956b8334f 100644 --- a/python-package/xgboost/data.py +++ b/python-package/xgboost/data.py @@ -909,9 +909,16 @@ 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_categorical_dtype, is_bool_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) and 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]