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:2624–2680  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

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