Skip to content

[Data] Fix OneHotEncoder max_categories to use global top-k instead of per-partition - #60790

Merged
alexeykudinkin merged 6 commits into
ray-project:masterfrom
xinyuangui2:fix-top-k-in-onehot
Feb 10, 2026
Merged

alexeykudinkin merged 6 commits into
ray-project:masterfrom
xinyuangui2:fix-top-k-in-onehot

Conversation

@xinyuangui2

@xinyuangui2 xinyuangui2 commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix compute_unique_value_indices to aggregate value counts globally across all partitions
    before applying max_categories top-k selection. Previously, top-k was applied
    per-partition and then unioned, which could miss categories that appear moderately across
    many partitions (e.g. a value with count 3 in two partitions has global count 6 but would be
    excluded if each partition only keeps its top-2).
  • Add docstring for compute_unique_value_indices documenting the global aggregation
    behavior and all parameters.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request fixes a bug in how top-k categories are computed when max_categories is used in encoders like OneHotEncoder. The previous implementation applied the top-k logic per partition, leading to incorrect global top-k results. The fix correctly aggregates value counts across all partitions before determining the top-k categories. A regression test is added to verify this fix. The changes look good and address the issue effectively. I have one minor suggestion to improve code clarity.

@xinyuangui2 xinyuangui2 changed the title Fix top k in onehot [Data] Fix OneHotEncoder max_categories to use global top-k instead of per-partition Feb 9, 2026
@xinyuangui2
xinyuangui2 marked this pull request as ready for review February 9, 2026 17:46
@xinyuangui2
xinyuangui2 requested a review from a team as a code owner February 9, 2026 17:46
@xinyuangui2 xinyuangui2 added the go add ONLY when ready to merge, run all tests label Feb 9, 2026
@alexeykudinkin
alexeykudinkin merged commit dd10a86 into ray-project:master Feb 10, 2026
3 checks passed
ans9868 pushed a commit to ans9868/ray that referenced this pull request Feb 18, 2026
…f per-partition (ray-project#60790)

## Summary
- Fix `compute_unique_value_indices` to aggregate value counts globally
across all partitions
before applying `max_categories` top-k selection. Previously, top-k was
applied
per-partition and then unioned, which could miss categories that appear
moderately across
many partitions (e.g. a value with count 3 in two partitions has global
count 6 but would be
  excluded if each partition only keeps its top-2).
- Add docstring for `compute_unique_value_indices` documenting the
global aggregation
  behavior and all parameters.

---------

Signed-off-by: xgui <[email protected]>
Signed-off-by: Adel Nour <[email protected]>
Aydin-ab pushed a commit to kunling-anyscale/ray that referenced this pull request Feb 20, 2026
…f per-partition (ray-project#60790)

## Summary
- Fix `compute_unique_value_indices` to aggregate value counts globally
across all partitions
before applying `max_categories` top-k selection. Previously, top-k was
applied
per-partition and then unioned, which could miss categories that appear
moderately across
many partitions (e.g. a value with count 3 in two partitions has global
count 6 but would be
  excluded if each partition only keeps its top-2).
- Add docstring for `compute_unique_value_indices` documenting the
global aggregation
  behavior and all parameters.

---------

Signed-off-by: xgui <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants