Skip to content

GH-55769: [C++][Python] Preserve leading NaNs in cumulative min and max - #55822

Closed
karthiksenv wants to merge 1 commit into
apache:mainfrom
karthiksenv:codex/55769-cumulative-leading-nan
Closed

karthiksenv wants to merge 1 commit into
apache:mainfrom
karthiksenv:codex/55769-cumulative-leading-nan

Conversation

@karthiksenv

@karthiksenv karthiksenv commented Nov 27, 2026 •

Copy link
Copy Markdown

Rationale for this change

With the default start, cumulative_max([NaN]) returns negative infinity and cumulative_min([NaN]) returns positive infinity. The corresponding aggregates return NaN.

What changes are included in this PR?

Use quiet NaN as the floating-point identity for min and max. The existing operators select the numeric operand when only one operand is NaN, so the first number establishes the running extremum. Update the function docs and point cumulative_mean at its own docstring so it does not inherit the maximum's NaN behavior in its documentation.

Are these changes tested?

Reproduced the bug with the PyArrow 25.0.1 and 26.0.1 wheels on macOS 15.8.2 arm64 with Python 3.12.10. On the patched source build, all 1,157 C++ vector tests passed. The reported Python examples passed for float32 and float64, as did checks for chunk boundaries, null handling, and explicit starts. Validation run

Are there any user-facing changes?

With the default start, a leading run of NaNs now produces NaNs. For example, cumulative_max([NaN, 1, NaN, 2]) returns [NaN, 1, 1, 2]. An explicit numeric start participates from the first element.

This PR contains a "Critical Fix". The previous default could introduce an infinity into a result even when the input contained only NaNs.

Was AI used for this PR?

AI wrote and reviewed the patch, tests, and description.

Closes #55769.

@karthiksenv
karthiksenv marked this pull request as ready for review November 27, 2026 22:45
@thisisnic

Copy link
Copy Markdown
Member

Closing this PR as it doesn't meet our guidelines on AI-generated contributions:

https://arrow.apache.org/docs/developers/overview.html#ai-generated-code

If you'd like to contribute this change, please review and test the code yourself, then open a new PR.

@thisisnic thisisnic closed this Nov 27, 2026
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.

[C++][Python] cumulative_max/cumulative_min emit the start value for leading NaN

2 participants