Skip to content

Support categorical features from polars.#11565

Merged
trivialfis merged 5 commits into
dmlc:masterfrom
trivialfis:cat-polars-1
Jul 16, 2025
Merged

Support categorical features from polars.#11565
trivialfis merged 5 commits into
dmlc:masterfrom
trivialfis:cat-polars-1

Conversation

@trivialfis

@trivialfis trivialfis commented Jul 16, 2025

Copy link
Copy Markdown
Member

Close #10554
Related: #11088

CPU-only at the moment.

@trivialfis

Copy link
Copy Markdown
Member Author

cc @rongou

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for categorical features from Polars DataFrames in XGBoost. Previously, when using Polars categorical data with XGBoost, a NotImplementedError was raised. Now categorical features are properly handled when enable_categorical=True is set.

Key changes:

  • Implement categorical feature handling for Arrow/Polars data structures
  • Add validation requiring enable_categorical=True for categorical data
  • Refactor Arrow array interface code for better modularity

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/python/test_with_polars.py Updates test to verify categorical feature support with Polars Categorical and Enum types
src/data/adapter.h Adds type validation for offset arrays in categorical data processing
python-package/xgboost/data.py Implements categorical support for Arrow tables and refactors array interface handling
python-package/xgboost/_data_utils.py Moves and enhances Arrow utility functions with categorical data support

Comment thread python-package/xgboost/_data_utils.py Outdated
Comment thread python-package/xgboost/_data_utils.py Outdated
Comment thread tests/python/test_with_polars.py
@trivialfis trivialfis merged commit 16e3cb5 into dmlc:master Jul 16, 2025
95 of 115 checks passed
@trivialfis trivialfis deleted the cat-polars-1 branch July 16, 2025 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XGBoost Fails with Polars DataFrames Containing Categorical Columns

3 participants