Adarsh-Me opened a new pull request, #51203:
URL: https://github.com/apache/arrow/pull/51203

   ## Rationale for this change
   
   `Identity<Max>` (the implicit default start of `cumulative_max`) used 
`std::numeric_limits<T>::min()`, which is the smallest **positive** value for 
floating-point types. Any input starting with a non-positive value therefore 
never replaced the start as the new maximum:
   
   ```python
   >>> import pyarrow as pa, pyarrow.compute as pc
   >>> pc.cumulative_max(pa.array([-2.5, 2.5])).to_pylist()
   [2.2250738585072014e-308, 2.5]   # expected [-2.5, 2.5]
   ```
   
   ## What changes are included in this PR?
   
   - `Identity<Max>` now uses `-infinity` for floating-point types (and 
half-float), and keeps `lowest()` for integer types. `-infinity` is the only 
value satisfying the documented identity property `Op(identity, x) = x for all 
x` — `lowest()` (most negative finite value) fails it for a leading `-inf` 
input.
   - `Identity<Min>` gets the mirror fix: `+infinity` for floating-point types. 
Previously `cumulative_min([inf, 1.0])` returned `[DBL_MAX, 1.0]` instead of 
`[inf, 1.0]`.
   
   Closes #51194.
   
   ## Are these changes tested?
   
   - Added `TestCumulative.NegativeValues` covering negative integers, negative 
floats, and `±Inf` inputs for both `cumulative_max` and `cumulative_min`.
   - Added a pyarrow regression test reproducing the issue 
(`test_cumulative_max_min_negative_default_start`).
   
   ## Are there any user-facing changes?
   
   Yes: `cumulative_max`/`cumulative_min` now return correct results for 
floating-point inputs whose first value is non-positive (for max) / 
non-negative or `inf` (for min). The documented behavior — 'the default start 
is the minimum/maximum value of input type' — is now actually honored.


-- 
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]

Reply via email to