Skip to content

Commit eb980fc

Browse files
authored
Fix categorical data check. (dmlc#11172)
1 parent 0d7821f commit eb980fc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

python-package/xgboost/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,12 +912,13 @@ def _arrow_feature_info(data: DataType) -> Tuple[List[str], List]:
912912

913913
def map_type(name: str) -> str:
914914
col = table.column(name)
915-
if isinstance(col, pa.DictionaryType):
915+
if isinstance(col.type, pa.DictionaryType):
916916
raise NotImplementedError(
917917
"Categorical feature is not yet supported with the current input data "
918918
"type."
919919
)
920920
return CAT_T # pylint: disable=unreachable
921+
921922
return _arrow_dtype()[col.type]
922923

923924
types = list(map(map_type, names))

tests/python/test_with_polars.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,13 @@ def test_regressor() -> None:
133133
predt1 = reg1.predict(X)
134134

135135
np.testing.assert_allclose(predt0, predt1)
136+
137+
def test_categorical() -> None:
138+
import polars as pl
139+
140+
df = pl.DataFrame(
141+
{"f0": [1, 2, 3], "b": ["a", "b", "c"]},
142+
schema=[("a", pl.Int64()), ("b", pl.Categorical())]
143+
)
144+
with pytest.raises(NotImplementedError, match="Categorical feature"):
145+
xgb.DMatrix(df, enable_categorical=True)

0 commit comments

Comments
 (0)