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

Function test_custom_collection

dask/tests/test_base.py:272–347  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

270
271
272def test_custom_collection():
273 dsk = {("x", h1): 1, ("x", h2): 2}
274 dsk2 = {("y", h1): (add, ("x", h1), ("x", h2)), ("y", h2): (add, ("y", h1), 1)}
275 dsk2.update(dsk)
276 dsk3 = {"z": (add, ("y", h1), ("y", h2))}
277 dsk3.update(dsk2)
278
279 w = Tuple({}, []) # A collection can have no keys at all
280 x = Tuple(dsk, [("x", h1), ("x", h2)])
281 y = Tuple(dsk2, [("y", h1), ("y", h2)])
282 z = Tuple(dsk3, ["z"])
283 # Collection with multiple names
284 t = w + x + y + z
285
286 # __slots__ defined on base mixin class propagates
287 with pytest.raises(AttributeError):
288 x.foo = 1
289
290 # is_dask_collection
291 assert is_dask_collection(w)
292 assert is_dask_collection(x)
293 assert is_dask_collection(y)
294 assert is_dask_collection(z)
295 assert is_dask_collection(t)
296
297 # tokenize
298 assert tokenize(w) == tokenize(w)
299 assert tokenize(x) == tokenize(x)
300 assert tokenize(y) == tokenize(y)
301 assert tokenize(z) == tokenize(z)
302 assert tokenize(t) == tokenize(t)
303 # All tokens are unique
304 assert len({tokenize(coll) for coll in (w, x, y, z, t)}) == 5
305
306 # get_collection_names
307 assert get_collection_names(w) == set()
308 assert get_collection_names(x) == {"x"}
309 assert get_collection_names(y) == {"y"}
310 assert get_collection_names(z) == {"z"}
311 assert get_collection_names(t) == {"x", "y", "z"}
312
313 # compute
314 assert w.compute() == ()
315 assert x.compute() == (1, 2)
316 assert y.compute() == (3, 4)
317 assert z.compute() == (7,)
318 assert dask.compute(w, [{"x": x}, y, z]) == ((), [{"x": (1, 2)}, (3, 4), (7,)])
319 assert t.compute() == (1, 2, 3, 4, 7)
320
321 # persist
322 t2 = t.persist()
323 assert isinstance(t2, Tuple)
324 assert t2._keys == t._keys
325 assert sorted(t2._dask.values()) == [1, 2, 3, 4, 7]
326 assert t2.compute() == (1, 2, 3, 4, 7)
327
328 w2, x2, y2, z2 = dask.persist(w, x, y, z)
329 assert y2._keys == y._keys

Callers

nothing calls this directly

Calls 9

__dask_postpersist__Method · 0.95
is_dask_collectionFunction · 0.90
get_collection_namesFunction · 0.90
setClass · 0.85
TupleClass · 0.70
tokenizeFunction · 0.50
computeMethod · 0.45
persistMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected