You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++] min/max aggregate for floating points can return values not contained in column #46063
changed the title [-]min/max aggregate for floating points can return values not contained in column[/-][+][C++] min/max aggregate for floating points can return values not contained in column[/+]on Apr 9, 2025
Despite whether we are doing so deliberately (most likely not), I don't think emitting -inf or inf is desirable for an all-NaN array. The proposed returning NaN sounds reasonable. I think current undesirable behavior is because we initialize our running min/max as -inf/inf. And by definition std::fmin/fmax(non-NaN, NaN) always emits non-NaN. I think I can work on a fix.
As a data point, NumPy has a function nanmin that ignores NaN when computing an array's minimum, but it still returns NaN if no other values are encountered (it also emits a warning):
We can simply initialize the running min/max to nan (instead of -inf/inf) and leverage the nice property of fmin/fmax that for all two nans return nan, otherwise the non-nan. And allowing empty array and all-nan array, that would be otherwise considered invalid in NumPy, shouldn't be much of a harm perhaps?
Activity
[-]min/max aggregate for floating points can return values not contained in column[/-][+][C++] min/max aggregate for floating points can return values not contained in column[/+]pitrou commentedon Jul 2, 2025
That sounds like a reasonable suggestion. We should make sure the current behavior is not deliberate, though. cc @zanmato1984
pitrou commentedon Jul 2, 2025
The current behavior has the nice property that it makes filtering using statistics easier than if NaN has to be handled explicitly.
zanmato1984 commentedon Jul 10, 2025
Despite whether we are doing so deliberately (most likely not), I don't think emitting
-inforinfis desirable for an all-NaN array. The proposed returning NaN sounds reasonable. I think current undesirable behavior is because we initialize our running min/max as-inf/inf. And by definitionstd::fmin/fmax(non-NaN, NaN)always emitsnon-NaN. I think I can work on a fix.pitrou commentedon Jul 10, 2025
As a data point, NumPy has a function
nanminthat ignores NaN when computing an array's minimum, but it still returns NaN if no other values are encountered (it also emits a warning):However, it also doesn't support an empty input array unless you pass an
initialargument, and then...Arrow on the other hand returns Null if an empty array is given:
Thought @jorisvandenbossche @bkietz @westonpace @WillAyd ?
zanmato1984 commentedon Jul 10, 2025
From the implementation perspective, I think the cheapest and reasonable solution is that we do:
We can simply initialize the running min/max to nan (instead of -inf/inf) and leverage the nice property of
fmin/fmaxthat for all two nans return nan, otherwise the non-nan. And allowing empty array and all-nan array, that would be otherwise considered invalid in NumPy, shouldn't be much of a harm perhaps?pitrou commentedon Jul 10, 2025
I would be ok with that. Let's perhaps wait for other opinions?
GH-46063: [C++][Compute] Fix the issue that MinMax kernel emits -inf/…
zanmato1984 commentedon Jan 7, 2026
Issue resolved by pull request 48459
#48459
apacheGH-46063: [C++][Compute] Fix the issue that MinMax kernel emits…
arrow: disable minmax reduction vectorization on riscv64