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

Function test_reduction_method

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

Source from the content-addressed store, hash-verified

2584
2585
2586def test_reduction_method():
2587 df = pd.DataFrame({"x": range(50), "y": range(50, 100)})
2588 ddf = dd.from_pandas(df, npartitions=4)
2589
2590 chunk = lambda x, val=0: (x >= val).sum()
2591 agg = lambda x: x.sum()
2592
2593 # Output of chunk is a scalar
2594 res = ddf.x.reduction(chunk, aggregate=agg)
2595 assert_eq(res, df.x.count())
2596
2597 # Output of chunk is a series
2598 res = ddf.reduction(chunk, aggregate=agg)
2599 assert res._name == ddf.reduction(chunk, aggregate=agg)._name
2600 assert_eq(res, df.count())
2601
2602 # Test with keywords
2603 res2 = ddf.reduction(chunk, aggregate=agg, chunk_kwargs={"val": 25})
2604 assert (
2605 res2._name
2606 == ddf.reduction(chunk, aggregate=agg, chunk_kwargs={"val": 25})._name
2607 )
2608 assert res2._name != res._name
2609 assert_eq(res2, (df >= 25).sum())
2610
2611 # Output of chunk is a dataframe
2612 def sum_and_count(x):
2613 return pd.DataFrame({"sum": x.sum(), "count": x.count()})
2614
2615 res = ddf.reduction(sum_and_count, aggregate=lambda x: x.groupby(level=0).sum())
2616
2617 assert_eq(res, pd.DataFrame({"sum": df.sum(), "count": df.count()}))
2618
2619
2620def test_reduction_method_split_every():

Callers

nothing calls this directly

Calls 5

assert_eqFunction · 0.90
sumMethod · 0.45
reductionMethod · 0.45
countMethod · 0.45
groupbyMethod · 0.45

Tested by

no test coverage detected