Skip to content

nancumsum result for numba and numpy does not match #79

Closed
@Illviljan

Description

@Illviljan
import numpy as np
import numpy_groupies as npg


s = npg.aggregate_numpy.aggregate(
    [0, 0, 0, 1, 1, 0, 0], [2, 2, np.nan, 2, 2, 2, 2], func="nancumsum"
)
ss = npg.aggregate_numba.aggregate(
    [0, 0, 0, 1, 1, 0, 0], [2, 2, np.nan, 2, 2, 2, 2], func="nancumsum"
)
np.testing.assert_allclose(s, ss)

AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0

(shapes (6,), (7,) mismatch)
 x: array([2., 4., 2., 4., 6., 8.])
 y: array([2., 4., 4., 2., 4., 6., 8.])

npg.__version__
Out[5]: '0.9.22'

Doesn't look like the nancumsum function is being chosen.

def _nancumsum(group_idx, a, size, fill_value=None, dtype=None):
a_nonans = np.where(np.isnan(a), 0, a)
group_idx_nonans = np.where(
np.isnan(group_idx), np.nanmax(group_idx) + 1, group_idx
)
return _cumsum(group_idx_nonans, a_nonans, size, fill_value=fill_value, dtype=dtype)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions