Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store categories from pandas. #11303

Merged
merged 2 commits into from
Mar 4, 2025
Merged

Store categories from pandas. #11303

merged 2 commits into from
Mar 4, 2025

Conversation

trivialfis
Copy link
Member

@trivialfis trivialfis commented Mar 3, 2025

  • Add Python glue code to fetch categories from pandas.
  • Add a getter to retrieve the categories from DMatrix.

Other DMatrix types are not supported yet.

@trivialfis
Copy link
Member Author

I need to either find a fix for the hang or disable the test.

@trivialfis
Copy link
Member Author

cc @rongou

tidy error is fixed in #11306

@@ -1240,6 +1251,70 @@ def get_quantile_cut(self) -> Tuple[np.ndarray, np.ndarray]:
assert data.dtype == np.float32
return indptr, data

def get_categories(self) -> Optional[Dict[str, "pa.DictionaryArray"]]:
Copy link
Member Author

Choose a reason for hiding this comment

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

We might one day generalize this into an arrow encoder/decoder. For now, it's just glue code.

@@ -718,6 +720,56 @@ XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field,
API_END();
}

XGB_DLL int XGBDMatrixGetCategories(DMatrixHandle handle, char const **out) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The function is hidden due to WIP.

- Change host columnar adapter to receive categories.
- Store categories in the meta info.
- Glue code for the Python interface.
@trivialfis trivialfis merged commit 4349d1d into dmlc:master Mar 4, 2025
55 of 56 checks passed
@trivialfis trivialfis deleted the cat-inputs branch March 4, 2025 22:06
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.

2 participants