Skip to content
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

Expand groupby_reduce property tests #385

Merged
merged 7 commits into from
Aug 14, 2024
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
2 changes: 1 addition & 1 deletion ci/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- build
- cachey
- dask-core
- numpy>=1.22
- numpy<2
- mamba
- pip
- python=3.10
Expand Down
2 changes: 1 addition & 1 deletion flox/aggregate_flox.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _np_grouped_op(

def _nan_grouped_op(group_idx, array, func, fillna, *args, **kwargs):
if fillna in [dtypes.INF, dtypes.NINF]:
fillna = dtypes._get_fill_value(kwargs.get("dtype", array.dtype), fillna)
fillna = dtypes._get_fill_value(kwargs.get("dtype", None) or array.dtype, fillna)
result = func(group_idx, np.where(isnull(array), fillna, array), *args, **kwargs)
# np.nanmax([np.nan, np.nan]) = np.nan
# To recover this behaviour, we need to search for the fillna value
Expand Down
24 changes: 24 additions & 0 deletions tests/test_asv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Run asv benchmarks as tests

import pytest

pytest.importorskip("dask")

from asv_bench.benchmarks import reduce


@pytest.mark.parametrize(
"problem", [reduce.ChunkReduce1D, reduce.ChunkReduce2D, reduce.ChunkReduce2DAllAxes]
)
def test_reduce(problem) -> None:
testcase = problem()
testcase.setup()
for args in zip(*testcase.time_reduce.params):
testcase.time_reduce(*args)


def test_reduce_bare() -> None:
testcase = reduce.ChunkReduce1D()
testcase.setup()
for args in zip(*testcase.time_reduce_bare.params):
testcase.time_reduce_bare(*args)
14 changes: 12 additions & 2 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def not_overflowing_array(array: np.ndarray[Any, Any]) -> bool:
return result


@given(data=st.data(), array=numeric_arrays, func=func_st)
@given(
data=st.data(),
array=st.one_of(numeric_arrays, chunked_arrays(arrays=numeric_arrays)),
func=func_st,
)
def test_groupby_reduce(data, array, func: str) -> None:
# overflow behaviour differs between bincount and sum (for example)
assume(not_overflowing_array(array))
Expand Down Expand Up @@ -93,7 +97,13 @@ def test_groupby_reduce(data, array, func: str) -> None:

# numpy-groupies always does the calculation in float64
if (
("var" in func or "std" in func or "sum" in func or "mean" in func)
(
"var" in func
or "std" in func
or "sum" in func
or "mean" in func
or "quantile" in func
)
and array.dtype.kind == "f"
and array.dtype.itemsize != 8
):
Expand Down
Loading