ray.data.Dataset.limit#

Dataset.limit(limit: int) ray.data.dataset.Dataset[ray.data.block.T][source]#

Truncate the dataset to the first limit records.

Contrary to :meth`.take`, this will not move any data to the caller’s machine. Instead, it will return a new Dataset pointing to the truncated distributed data.

Examples

>>> import ray
>>> ds = ray.data.range(1000)
>>> ds.limit(100).map(lambda x: x * 2).take()
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]

Time complexity: O(limit specified)

Parameters

limit – The size of the dataset to truncate to.

Returns

The truncated dataset.