class_docstr: Adapter that handles python generators and iterators.
class_docstr_tok: ["Adapter","that","handles","python","generators","and","iterators","."]
code: def __init__(
      self,
      x: tp.Union[tp.Iterable],
      y=None,
      sample_weights=None,
      **kwargs,
  ):
      # Generators should never shuffle as exhausting the generator in order to
      # shuffle the batches is inefficient.
      kwargs.pop("shuffle", None)
  
      if not is_none_or_empty(y):
          raise ValueError(
              "`y` argument is not supported when using "
              "python generator as input."
          )
      if not is_none_or_empty(sample_weights):
          raise ValueError(
              "`sample_weight` argument is not supported when using "
              "python generator as input."
          )
  
      super(GeneratorDataAdapter, self).__init__(x, y, **kwargs)
  
      # Since we have to know the dtype of the python generator when we build the
      # dataset, we have to look at a batch to infer the structure.
      peek, x = self._peek_and_restore(x)
      assert_not_namedtuple(peek)
      peek = self._standardize_batch(peek)
  
      self._first_batch_size = int(list(flatten(peek))[0].shape[0])
  
      def wrapped_generator():
          for data in x:
              yield self._standardize_batch(data)
  
      dataset = wrapped_generator
  
      self._dataset = dataset
  
file_path: elegy/elegy/data/generator_adapter.py
imports: import itertools
  import typing
  from .data_adapter import DataAdapter
  from .utils import assert_not_namedtuple, flatten, is_none_or_empty, pack_x_y_sample_weight, unpack_x_y_sample_weight
label_desc: Use image node_id 2 to create a new GeneratorDataAdapter object from inherited base classes: DataAdapter with example: obj = GeneratorDataAdapter(x, y, sample_weights)