Skip to content

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

Backlog

Description

@FBruzzesi

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.

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

Activity

  1. changed the title [-]`cumulative_max`/`cumulative_min` emit the start value for leading NaN[/-] [+][C++][Python] `cumulative_max`/`cumulative_min` emit the start value for leading NaN[/+] on Nov 24, 2026
  2. pierceluu10 commented on Nov 28, 2026

    @pierceluu10

    take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions