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

Function test_reduction_method

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

Source from the content-addressed store, hash-verified

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