FBruzzesi opened a new issue, #55769:
URL: https://github.com/apache/arrow/issues/55769
### Describe the bug, including details regarding any error messages,
version, and platform.
### Describe the bug, including details regarding any error messages,
version, and platform.
`cumulative_max` and `cumulative_min` on a floating-point input return the
start value at every NaN position that comes before the first non-NaN value.
With the default start, that is `-inf` for `cumulative_max` and `inf` for
`cumulative_min`, values that do not appear in the input.
```python
import pyarrow as pa
import pyarrow.compute as pc
nan = float("nan")
for values in ([nan, 1.0, 2.0], [nan], [nan, nan, 1.0], [1.0, nan, 2.0]):
arr = pa.array(values, pa.float64())
print(values, pc.cumulative_max(arr).to_pylist(),
pc.cumulative_min(arr).to_pylist())
print(pc.max(pa.array([nan])).as_py())
```
With pyarrow 26.0.1:
```
[nan, 1.0, 2.0] [-inf, 1.0, 2.0] [inf, 1.0, 1.0]
[nan] [-inf] [inf]
[nan, nan, 1.0] [-inf, -inf, 1.0] [inf, inf, 1.0]
[1.0, nan, 2.0] [1.0, 1.0, 2.0] [1.0, 1.0, 1.0]
nan
```
float32 behaves the same. On pyarrow 25.0.1 the leaked value is the old
finite seed instead (`2.2250738585072014e-308` and `1.7976931348623157e+308`,
see #51194). So #51203 changed which value leaks, but not the leak itself.
NaN later in the input is ignored, which is consistent with how the
`max`/`min` aggregates and `max_element_wise` treat NaN. The leading case is
not consistent with them: `pc.max([nan])` returns `nan`, while
`cumulative_max([nan])` returns `-inf`. The docstring says the default start is
chosen "so that any other value will replace the start as the new maximum",
which does not hold for NaN.
Expected: a NaN before any non-NaN value is emitted as NaN, so
`cumulative_max([nan, 1.0, 2.0])` gives `[nan, 1.0, 2.0]` and
`cumulative_max([nan])` gives `[nan]`, matching `pc.max`. Polars returns
exactly that for its `cum_max`/`cum_min`. An explicit user-supplied `start`
could reasonably keep the current behaviour, since there the start is a real
value.
Found while working around #51194 in Narwhals (narwhals-dev/narwhals#4033).
Platform: macOS arm64, Python 3.12, pyarrow 25.0.1 and 26.0.1 from PyPI.
### Component(s)
C++, Python
--
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]