Repository navigation
Open
Labels
bugSomething isn't working
Milestone
Description
Fix GroupBy aggregate skipna behavior for all-NaN groups
Summary
Arkouda GroupBy.aggregate(..., skipna=True) does not currently match pandas behavior for groups containing only NaN values.
Specifically:
maxreturns-np.finfo(np.float64).max(sentinel value)minmay returnNaN
In pandas, both groupby().max(skipna=True) and groupby().min(skipna=True) return NaN for groups with no valid (non-NaN) values.
This discrepancy causes pandas-equivalency tests to fail and forces test-side hacks.
Expected Behavior (pandas-compatible)
For floating-point reductions with skipna=True:
- Ignore NaNs during reduction
- If a group has zero non-NaN elements, the result must be NaN
This should apply consistently to:
minmax- (potentially other reductions with identities)
Current Behavior
max: NaNs are replaced by a sentinel (-1.7976931348623157e+308) and never restoredmin: Behavior is inconsistent; sometimes returns NaN
Acceptance Criteria
- Arkouda
GroupBy.aggregate(..., op, skipna=True)matches pandas forminandmax - All-NaN groups return NaN
- Pandas equivalency tests pass without test-side NaN rewriting
- Behavior is consistent across ops
Related Tests
tests/pandas/groupby_test.py::TestGroupBy::test_pandas_equivalency_nan
Notes
This fix aligns Arkouda semantics with pandas and NumPy expectations and removes the need for sentinel-based test adjustments.
Minimal Repro Example (pandas vs Arkouda)
Setup
>>> import arkouda as ak
>>> import numpy as np
>>> import pandas as pdData: one group is all-NaN
>>> keys = np.array([0, 0, 1, 1])
>>> vals = np.array([1.0, np.nan, np.nan, np.nan], dtype=np.float64)
>>> df = pd.DataFrame({"keys": keys, "vals": vals})
>>> ak_keys = ak.array(keys)
>>> ak_vals = ak.array(vals)
>>> akg = ak.GroupBy(ak_keys)pandas (default behavior): all-NaN groups return NaN
Note:
GroupBy.max/mindo not accept askipnakeyword.
NaN-skipping is the default pandas behavior.
>>> df.groupby("keys")["vals"].max().to_numpy()
array([ 1., nan])
>>> df.groupby("keys")["vals"].min().to_numpy()
array([ 1., nan])Arkouda (skipna=True today): max returns a sentinel for all-NaN groups
>>> ak_out_keys, ak_out_max = akg.aggregate(ak_vals, "max", True)
>>> ak_out_keys.to_ndarray()
array([0, 1])
>>> ak_out_max.to_ndarray()
# Expected: [1.0, nan]
# Actual today: [1.0, -1.7976931348623157e+308]
array([ 1.00000000e+000, -1.79769313e+308])Expected Arkouda output (pandas-compatible)
- For
skipna=True, bothminandmaxshould returnNaNwhen a group has no non-NaN values.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
ajpotts commentedon Jan 8, 2026
Related to: #5050
add xfail for issue 5262 (#5263)