josamhany opened a new pull request, #55612:
URL: https://github.com/apache/arrow/pull/55612
### Rationale for this change
Passing a negative value to `Dataset.head()` can result in unexpected
behavior, including returning a table with a negative number of rows.
Since the `head()` API expects a non-negative number of rows, negative
values should be rejected explicitly with a clear error message.
### What changes are included in this PR?
- Added validation in `AsyncScanner::Head()` to reject negative `num_rows`
values.
- Returns `Status::Invalid("num_rows must be non-negative")` when a negative
value is provided.
- Added regression tests covering negative values passed to:
- `Dataset.head()`
- `Scanner.head()`
- `Fragment.head()`
### Are these changes tested?
Yes.
- Built PyArrow from source successfully.
- Targeted tests: **3 passed**.
- Full `python/pyarrow/tests/test_dataset.py` test suite: **310 passed, 54
skipped**.
- `git diff --check` passed.
### Are there any user-facing changes?
Yes. Calling `Dataset.head()`, `Scanner.head()`, or `Fragment.head()` with a
negative `num_rows` now raises `pyarrow.ArrowInvalid` with a clear error
message instead of producing unexpected behavior.
### Was AI used for this PR?
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]