gluonts.itertools module

class gluonts.itertools.Cached(iterable: Iterable)[source]

Bases: collections.abc.Iterable, typing.Generic

An iterable wrapper, which caches values in a list the first time it is iterated.

The primary use-case for this is to avoid re-computing the element of the sequence, in case the inner iterable does it on demand.

This should be used to wrap deterministic iterables, i.e. iterables where the data generation process is not random, and that yield the same elements when iterated multiple times.

class gluonts.itertools.Cyclic(iterable: Iterable)[source]

Bases: collections.abc.Iterable, typing.Generic

Like itertools.cycle, but does not store the data.

class gluonts.itertools.IterableSlice(iterable: Iterable, length: Optional[int])[source]

Bases: collections.abc.Iterable, typing.Generic

An iterable version of itertools.islice, i.e. one that can be iterated over multiple times.

class gluonts.itertools.PseudoShuffled(iterable: Iterable, shuffle_buffer_length: int)[source]

Bases: collections.abc.Iterable, typing.Generic

Yields items from a given iterable in a pseudo-shuffled order.

gluonts.itertools.batcher(iterable: Iterable[T], batch_size: int) → Iterator[List[T]][source]

Groups elements from iterable into batches of size batch_size.

>>> list(batcher("ABCDEFG", 3))
[['A', 'B', 'C'], ['D', 'E', 'F'], ['G']]

Unlike the grouper proposed in the documentation of itertools, batcher doesn’t fill up missing values.