()
| 2618 | |
| 2619 | |
| 2620 | def test_reduction_method_split_every(): |
| 2621 | df = pd.Series([1] * 60) |
| 2622 | ddf = dd.from_pandas(df, npartitions=15) |
| 2623 | |
| 2624 | def chunk(x, constant=0): |
| 2625 | return x.sum() + constant |
| 2626 | |
| 2627 | def combine(x, constant=0): |
| 2628 | return x.sum() + constant + 1 |
| 2629 | |
| 2630 | def agg(x, constant=0): |
| 2631 | return x.sum() + constant + 2 |
| 2632 | |
| 2633 | f = lambda n: ddf.reduction( |
| 2634 | chunk, |
| 2635 | aggregate=agg, |
| 2636 | combine=combine, |
| 2637 | chunk_kwargs=dict(constant=1.0), |
| 2638 | combine_kwargs=dict(constant=2.0), |
| 2639 | aggregate_kwargs=dict(constant=3.0), |
| 2640 | split_every=n, |
| 2641 | ) |
| 2642 | |
| 2643 | assert_max_deps(f(3), 3) |
| 2644 | assert_max_deps(f(4), 4, False) |
| 2645 | assert_max_deps(f(5), 5) |
| 2646 | assert f(15).dask.keys() == f(ddf.npartitions).dask.keys() |
| 2647 | |
| 2648 | r3 = f(3) |
| 2649 | r4 = f(4) |
| 2650 | assert r3._name != r4._name |
| 2651 | |
| 2652 | # Keywords are different for each step |
| 2653 | assert f(3).compute() == 60 + 15 + 7 * (2 + 1) + (3 + 2) |
| 2654 | # Keywords are same for each step |
| 2655 | res = ddf.reduction( |
| 2656 | chunk, aggregate=agg, combine=combine, constant=3.0, split_every=3 |
| 2657 | ) |
| 2658 | assert res.compute() == 60 + 15 * 3 + 7 * (3 + 1) + (3 + 2) |
| 2659 | # No combine provided, combine is agg |
| 2660 | res = ddf.reduction(chunk, aggregate=agg, constant=3.0, split_every=3) |
| 2661 | assert res.compute() == 60 + 15 * 3 + 8 * (3 + 2) |
| 2662 | |
| 2663 | # split_every must be >= 2 |
| 2664 | with pytest.raises(ValueError): |
| 2665 | f(1) |
| 2666 | |
| 2667 | # combine_kwargs with no combine provided |
| 2668 | with pytest.raises(ValueError): |
| 2669 | ddf.reduction( |
| 2670 | chunk, |
| 2671 | aggregate=agg, |
| 2672 | split_every=3, |
| 2673 | chunk_kwargs=dict(constant=1.0), |
| 2674 | combine_kwargs=dict(constant=2.0), |
| 2675 | aggregate_kwargs=dict(constant=3.0), |
| 2676 | ) |
| 2677 |
nothing calls this directly
no test coverage detected
searching dependent graphs…