Skip to content

GH-51145: [Python] Accept Arrow integer scalars in slice methods - #51160

Open
YusefSyed wants to merge 1 commit into
apache:mainfrom
YusefSyed:codex/gh-51145-arrow-integer-slice
Open

GH-51145: [Python] Accept Arrow integer scalars in slice methods#51160
YusefSyed wants to merge 1 commit into
apache:mainfrom
YusefSyed:codex/gh-51145-arrow-integer-slice

Conversation

@YusefSyed

@YusefSyed YusefSyed commented Sep 4, 2026

Copy link
Copy Markdown

Rationale for this change

Array.slice, ChunkedArray.slice, RecordBatch.slice, and Table.slice
accept Python and NumPy integer-like values but reject Arrow integer scalars,
even though those scalars implement Python's integer-index protocol. This makes
values produced by Arrow APIs unnecessarily unusable as slice offsets and
lengths.

What changes are included in this PR?

Normalize non-None offsets and lengths with operator.index() at the four
public Python wrapper boundaries before the existing validation and C++ calls.

Add regression coverage for all signed and unsigned Arrow integer scalar types
across the four wrappers, plus NumPy compatibility, invalid and null scalars,
negative values, offset clamping, and int64 overflow behavior.

Are these changes tested?

Yes. Current Arrow C++ and editable PyArrow were built from source in an
isolated Python 3.13 environment. The focused new tests and existing slice
controls passed: 48 passed.

Cython translation, Python test-file compilation, Flake8, and
git diff --check also passed.

Are there any user-facing changes?

Yes. The four Python .slice() methods now accept non-null Arrow integer
scalars for offsets and lengths. Existing Python/NumPy integer behavior and
error behavior for unsupported values are preserved.

AI assistance

AI assisted analysis, implementation, test drafting, build work, and review.
The account holder reviewed and approved the final four-file diff. The account
holder did not personally run the commands reported above.

@YusefSyed
YusefSyed marked this pull request as ready for review September 4, 2026 15:58
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.

1 participant