Skip to content

[Data] Make Polars sort place nulls last - #66925

Merged
owenowenisme merged 3 commits into
ray-project:masterfrom
viiccwen:fix/sort-null-ording-inconsistent
Oct 13, 2026
Merged

owenowenisme merged 3 commits into
ray-project:masterfrom
viiccwen:fix/sort-null-ording-inconsistent

Conversation

@viiccwen

Copy link
Copy Markdown
Contributor

Description

Ray Data's Arrow and Pandas sorting paths place null values after non-null values. The Polars implementation used its backend default instead, so enabling DataContext.use_polars_sort changed the result order and could change the rows selected by sort(...).limit(k).

Pass nulls_last=True to the Polars local-sort and concatenated merge-sort paths. Then, add regressions for Arrow and Polars in ascending and descending order, covering local sorting, cross-block merging, and a four-input/four-output
partition Dataset sort.

Related issues

Closes #66841

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@viiccwen
viiccwen requested a review from a team as a code owner October 12, 2026 02:14

@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 updates Polars sorting operations in Ray Data to ensure null values are sorted last by passing nulls_last=True to Polars' sort function, and adds corresponding unit tests. The reviewer pointed out that the nulls_last parameter was introduced in Polars version 0.16.4 and using it with older versions will raise a TypeError. They suggested dynamically constructing the sorting keyword arguments based on the installed Polars version to maintain backward compatibility.

viiccwen added a commit to viiccwen/ray that referenced this pull request Oct 12, 2026
Propagate DataContext to the final merge task, preserve non-positive Limit plans, and defer the Polars rewrite until null ordering is aligned by ray-project#66925. Add regression coverage for these cases.

Signed-off-by: viiccwen <[email protected]>
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Oct 12, 2026

@owenowenisme owenowenisme left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but I would make df sort a helper function and add a few comments describing behavior.

@viiccwen

Copy link
Copy Markdown
Contributor Author

Hello @owenowenisme, thanks for reviewing. I already updated, PTAL.

@owenowenisme owenowenisme left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@owenowenisme
owenowenisme enabled auto-merge (squash) October 13, 2026 08:55
@github-actions
github-actions Bot disabled auto-merge October 13, 2026 08:55
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label Oct 13, 2026
@owenowenisme
owenowenisme merged commit 3c9eb48 into ray-project:master Oct 13, 2026
8 checks passed
viiccwen added a commit to viiccwen/ray that referenced this pull request Oct 13, 2026
Propagate DataContext to the final merge task, preserve non-positive Limit plans, and defer the Polars rewrite until null ordering is aligned by ray-project#66925. Add regression coverage for these cases.

Signed-off-by: viiccwen <[email protected]>
@viiccwen
viiccwen deleted the fix/sort-null-ording-inconsistent branch October 13, 2026 11:34
viiccwen added a commit to viiccwen/ray that referenced this pull request Oct 28, 2026
Propagate DataContext to the final merge task, preserve non-positive Limit plans, and defer the Polars rewrite until null ordering is aligned by ray-project#66925. Add regression coverage for these cases.

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

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Make null ordering consistent between Arrow/Pandas and Polars sort

2 participants