Repository navigation
GH-55769: [C++] Use NaN as the floating-point identity for cumulative_max/min - #55832
Open
pierceluu10 wants to merge 1 commit into
Open
pierceluu10 wants to merge 1 commit into
pierceluu10 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
With the default start,
cumulative_maxandcumulative_minon floating-point input emit-inf/inffor every NaN before the first non-NaN value, socumulative_max([NaN])returns[-inf]whilemax([NaN])returnsNaN.The default start comes from
Identity<Max>/Identity<Min>, which since GH-51194 return-inf/+inffor floating-point types.MaxandMinreturn the other operand when one side is NaN, soMax(-inf, NaN)is-infand the identity propertyOp(identity, x) == xdoes not hold for NaN. NaN does satisfy it for every input, including NaN and the infinities.What changes are included in this PR?
Identity<Max>andIdentity<Min>return quiet NaN for floating-point types. Integer types are unchanged.Identityis only used for the default start invector_cumulative_ops.cc, so no other kernel is affected.An explicit
startis unchanged: it is a real value and still applies from the first element, as suggested in the issue.Are these changes tested?
Yes.
TestCumulative.NaNnow checks leading NaNs for float32 and float64 with the default start, and that an explicit start still applies to them.test_cumulative_max_min_leading_nancovers the same case on a chunked array whose first chunk is all NaN.Both new tests fail on main (C++ got
-inf/infwhere NaN was expected; the Python test fails on pyarrow 26.0.1) and pass with this change.arrow-compute-vector-testpasses (1157 tests), and the cumulative tests intest_compute.pypass. I also checked empty input, all-NaN input, nulls with and withoutskip_nulls, sliced arrays, chunked arrays with empty chunks, integer input and explicit starts of0,NaNand-infby hand. Tested on macOS arm64.Are there any user-facing changes?
Yes. With the default start, leading NaNs in floating-point input now produce NaN, e.g.
cumulative_max([NaN, 1, NaN, 2])returns[NaN, 1, 1, 2]instead of[-inf, 1, 1, 2]. Results after the first non-NaN value are unchanged.Was AI used for this PR?
Yes. I used Claude Code to reproduce the issue and draft the change, the tests and this description. I went through the diff and checked the identity argument myself (
Max/Minpick the non-NaN operand, so NaN is the only value withOp(identity, x) == xfor every floatx), and reran the C++ and Python tests locally.PR code and description written by:
Reviewed before submission by: