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

Function test_reduction_method

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

Source from the content-addressed store, hash-verified

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