Skip to content

Switch back to ravel_multi_index. #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions numpy_groupies/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_scalar_input(aggregate_all, func):
np.testing.assert_array_equal(res, ref)


@pytest.mark.parametrize("func", ["sum", "prod", "mean", "var", "std" , "all", "any"])
@pytest.mark.parametrize("func", ["sum", "prod", "mean", "var", "std", "all", "any"])
def test_nan_input(aggregate_all, func, groups=100):
if aggregate_all.__name__.endswith('pandas'):
pytest.skip("pandas automatically skip nan values")
Expand Down Expand Up @@ -354,6 +354,25 @@ def test_agg_along_axis(aggregate_all, size, func, axis):
np.testing.assert_allclose(actual.squeeze(), expected)


def test_not_last_axis_reduction(aggregate_all):
x = np.array([
[1., 2.],
[4., 4.],
[5., 2.],
[np.nan, 3.],
[8., 7.]]
)
group_idx = np.array([1, 2, 2, 0, 1])
func = 'nanmax'
fill_value = np.nan
axis = 0
actual = aggregate_all(group_idx, x, axis=axis, func=func, fill_value=fill_value)
expected = np.array([[np.nan, 3.],
[8., 7.],
[5., 4.]])
np.testing.assert_allclose(expected, actual)


def test_custom_callable(aggregate_all):
def sum_(array):
return array.sum()
Expand All @@ -379,6 +398,7 @@ def test_argreduction_nD_array_1D_idx(aggregate_all):
expected = np.array([[0, 5, 2], [0, 5, 2]])
np.testing.assert_equal(actual, expected)


@pytest.mark.xfail(reason="fails for numba, pandas")
def test_argreduction_negative_fill_value(aggregate_all):
labels = np.array([0, 0, 2, 2, 2, 1, 1, 2, 2, 1, 1, 0], dtype=int)
Expand All @@ -388,7 +408,7 @@ def test_argreduction_negative_fill_value(aggregate_all):
np.testing.assert_equal(actual, expected)


@pytest.mark.parametrize("nan_inds", (None, tuple([[1, 4, 5], Ellipsis]), tuple((1,(0, 1, 2, 3)))))
@pytest.mark.parametrize("nan_inds", (None, tuple([[1, 4, 5], Ellipsis]), tuple((1, (0, 1, 2, 3)))))
@pytest.mark.parametrize("ddof", (0, 1))
@pytest.mark.parametrize("func", ("nanvar", "nanstd"))
def test_var_with_nan_fill_value(aggregate_all, ddof, nan_inds, func):
Expand Down
2 changes: 1 addition & 1 deletion numpy_groupies/utils_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def offset_labels(group_idx, inshape, axis, order, size):


def input_validation(group_idx, a, size=None, order='C', axis=None,
ravel_group_idx=True, check_bounds=True, method="offset", func=None):
ravel_group_idx=True, check_bounds=True, method="ravel", func=None):
""" Do some fairly extensive checking of group_idx and a, trying to
give the user as much help as possible with what is wrong. Also,
convert ndim-indexing to 1d indexing.
Expand Down