Skip to content

GH-55758: [Python] Buggy top_k_unstable/bottom_k_unstable - #55759

Open
AlenkaF wants to merge 1 commit into
apache:mainfrom
AlenkaF:buggy-top_k_unstable-bottom_k_unstable
Open

AlenkaF wants to merge 1 commit into
apache:mainfrom
AlenkaF:buggy-top_k_unstable-bottom_k_unstable

Conversation

@AlenkaF

@AlenkaF AlenkaF commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

top_k_unstable/bottom_k_unstable functions behavior is buggy.

What changes are included in this PR?

New _select_k_sort_keys helper is defined to update the current handling of options in top_k_unstable/bottom_k_unstable functions.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

Was AI used for this PR?

Yes, I used Claude to write up changes I wanted and to add a test. I have revised the suggestion and run the checks.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@AlenkaF
AlenkaF requested review from raulcd and rok as code owners November 24, 2026 13:03
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:03

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.

🟢 Approval recommended

No active review issues remain for the changes centralizing PyArrow’s top- and bottom-k option handling.

No open issues 🎉

What changed in this PR

This PR addresses GH-55758 by centralizing option handling for PyArrow’s top_k_unstable and bottom_k_unstable functions.

Changes:

  • Adds a shared helper that defaults table sort keys’ null placement to "at_end".
  • Validates option types and matching lengths, and rejects sort keys for Arrow array inputs without mutating caller-provided lists.
  • Updates parameter documentation and adds regression tests for defaults and validation errors.
File Description
python/​pyarrow/​tests/​test_compute.py Adds regression tests for default null placement, invalid options, and list preservation.
python/​pyarrow/​compute.py Introduces shared option handling, updates both wrappers, and clarifies their documentation.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants