def batched(iterable: Iterable[_T_co], n: int) -> Iterator[tuple[_T_co, ...]]:
    """Batch data into tuples of length n. The last batch may be shorter."""
    # Based on: https://docs.python.org/3/library/itertools.html#itertools-recipes
    # batched('ABCDEFG', 3) --> ABC DEF G
    if n < 1:
        raise ValueError("Batch size must be at least one")
    it = iter(iterable)
    while batch := tuple(islice(it, n)):
        yield batch
Batch data into tuples of length n. The last batch may be shorter.
src/datachain/utils.py