[enc] Expose categories container into Python.#11591
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR exposes the categories container into Python by creating a new Python class wrapper and making pyarrow optional for categorical data handling. The changes refactor the categories API to return a container object instead of direct pyarrow arrays, while maintaining backwards compatibility through the export_to_arrow parameter.
Key changes:
- Refactor C API to use opaque handles for category containers with separate memory management
- Add a new Python
Categoriesclass that wraps the C++ container and provides controlled access to arrow exports - Make pyarrow dependency optional by allowing category containers to be created without immediate arrow conversion
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/c_api/c_api.cc | Adds new C API functions for category container creation, export, and cleanup with handle-based memory management |
| src/data/data.cc | Updates function signature for SparsePage::Push method with type changes |
| include/xgboost/data.h | Updates header declaration to match implementation changes |
| python-package/xgboost/core.py | Refactors get_categories methods to return Categories objects and handle optional arrow export |
| python-package/xgboost/_data_utils.py | Implements new Categories class with handle management and arrow export functionality |
| python-package/xgboost/_typing.py | Adds new type aliases for arrow category data structures |
| python-package/xgboost/testing/ordinal.py | Updates all test code to use new Categories API with export_to_arrow parameter |
Member
Author
|
cc @rongou . |
20 tasks
rongou
approved these changes
Jul 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref #11088