MCPcopy Create free account
hub / github.com/dask/dask / test_reduction_method_split_every

Function test_reduction_method_split_every

dask/dataframe/tests/test_dataframe.py:2622–2678  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

assert_max_depsFunction · 0.90
fFunction · 0.70
reductionMethod · 0.45
keysMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected