MCPcopy
hub / github.com/dask/dask / test_fold

Function test_fold

dask/bag/tests/test_bag.py:263–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

261
262
263def test_fold():
264 c = b.fold(add)
265 assert c.compute() == sum(L)
266 assert c.key == b.fold(add).key
267
268 c2 = b.fold(add, initial=10)
269 assert c2.key != c.key
270 assert c2.compute() == sum(L) + 10 * b.npartitions
271 assert c2.key == b.fold(add, initial=10).key
272
273 c = db.from_sequence(range(5), npartitions=3)
274
275 def binop(acc, x):
276 acc = acc.copy()
277 acc.add(x)
278 return acc
279
280 d = c.fold(binop, set.union, initial=set())
281 assert d.compute() == set(c)
282 assert d.key == c.fold(binop, set.union, initial=set()).key
283
284 d = db.from_sequence("hello")
285 assert set(d.fold(lambda a, b: "".join([a, b]), initial="").compute()) == set(
286 "hello"
287 )
288
289 e = db.from_sequence([[1], [2], [3]], npartitions=2)
290 assert set(e.fold(add, initial=[]).compute(scheduler="sync")) == {1, 2, 3}
291
292
293def test_fold_bag():

Callers

nothing calls this directly

Calls 5

setClass · 0.85
foldMethod · 0.80
sumFunction · 0.50
computeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…