dask.bag.Bag.take

dask.bag.Bag.take

Bag.take(k, npartitions=1, compute=True, warn=True)[source]

Take the first k elements.

Parameters
kint

The number of elements to return

npartitionsint, optional

Elements are only taken from the first npartitions, with a default of 1. If there are fewer than k rows in the first npartitions a warning will be raised and any found rows returned. Pass -1 to use all partitions.

computebool, optional

Whether to compute the result, default is True.

warnbool, optional

Whether to warn if the number of elements returned is less than requested, default is True.

>>> import dask.bag as db
>>> b = db.from_sequence(range(1_000))
>>> b.take(3)
(0, 1, 2)