Skip to content

Commit

Permalink
Merge pull request #63 from dantegd/fix-backport-pd2-patch
Browse files Browse the repository at this point in the history
FIX Backport pandas 2 patch
  • Loading branch information
jakirkham authored May 29, 2024
2 parents b305c79 + d0aea27 commit a559727
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
46 changes: 46 additions & 0 deletions recipe/0004-pandas2-patch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/python-package/xgboost/data.py b/python-package/xgboost/data.py
index 0022a17d4..f1c7f55e2 100644
--- a/python-package/xgboost/data.py
+++ b/python-package/xgboost/data.py
@@ -770,9 +770,19 @@ def _cudf_array_interfaces(data: DataType, cat_codes: list) -> bytes:

"""
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")}
+ )

interfaces = []

diff --git a/tests/python-gpu/test_from_cudf.py b/tests/python-gpu/test_from_cudf.py
index 610c717a9..122fa8171 100644
--- a/tests/python-gpu/test_from_cudf.py
+++ b/tests/python-gpu/test_from_cudf.py
@@ -74,16 +74,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
3 changes: 2 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set name = "xgboost" %}
{% set version = "2.0.3" %}
{% set build_number = 4 %}
{% set build_number = 5 %}

package:
name: xgboost-split
Expand All @@ -16,6 +16,7 @@ source:
- 0001-Force-endian-flag-in-cross-compilation-mode.patch # [arm64 or aarch64 or ppc64le]
- 0002-Enable-latest-libcxx-on-MacOS.patch # [osx]
- 0003-Use-mingw-w64-path.patch
- 0004-pandas2-patch.patch

build:
number: {{ build_number }}
Expand Down

0 comments on commit a559727

Please sign in to comment.