class_docstr: An iterator for reading records from a :class:`~Dataset`.
  
  For Datasets, each iteration call represents a complete read of all items in the
  Dataset.
  
  If using Ray Train, each trainer actor should get its own iterator by calling
  :meth:`ray.train.get_dataset_shard("train")
  <ray.train.get_dataset_shard>`.
  
  Examples:
      >>> import ray
      >>> ds = ray.data.range(5)
      >>> ds
      Dataset(num_blocks=..., num_rows=5, schema={id: int64})
      >>> ds.iterator()
      DataIterator(Dataset(num_blocks=..., num_rows=5, schema={id: int64}))
class_docstr_tok: ["An","iterator","for","reading","records","from","a",":","class",":","`","~Dataset","`",".","For","Datasets",",","each","iteration","call","represents","a","complete","read","of","all","items","in","the","Dataset",".","If","using","Ray","Train",",","each","trainer","actor","should","get","its","own","iterator","by","calling",":","meth",":","`","ray.train.get_dataset_shard","(","``","train","''",")","<","ray.train.get_dataset_shard",">","`",".","Examples",":",">",">",">","import","ray",">",">",">","ds","=","ray.data.range","(","5",")",">",">",">","ds","Dataset","(","num_blocks=","...",",","num_rows=5",",","schema=","{","id",":","int64","}",")",">",">",">","ds.iterator","(",")","DataIterator","(","Dataset","(","num_blocks=","...",",","num_rows=5",",","schema=","{","id",":","int64","}",")",")"]
docstr: Return a batched iterable over the dataset.
  
  Examples:
      >>> import ray
      >>> for batch in ray.data.range(
      ...     1000000
      ... ).iterator().iter_batches(): # doctest: +SKIP
      ...     print(batch) # doctest: +SKIP
  
  Time complexity: O(1)
  
  Args:
      prefetch_batches: The number of batches to fetch ahead of the current batch
          to fetch. If set to greater than 0, a separate threadpool will be used
          to fetch the objects to the local node, format the batches, and apply
          the collate_fn. Defaults to 1.
      batch_size: The number of rows in each batch, or None to use entire blocks
          as batches (blocks may contain different number of rows).
          The final batch may include fewer than ``batch_size`` rows if
          ``drop_last`` is ``False``. Defaults to 256.
      batch_format: Specify ``"default"`` to use the default block format
          (NumPy), ``"pandas"`` to select ``pandas.DataFrame``, "pyarrow" to
          select ``pyarrow.Table``, or ``"numpy"`` to select
          ``Dict[str, numpy.ndarray]``, or None to return the underlying block
          exactly as is with no additional formatting.
      drop_last: Whether to drop the last batch if it's incomplete.
      local_shuffle_buffer_size: If non-None, the data will be randomly shuffled
          using a local in-memory shuffle buffer, and this value will serve as the
          minimum number of rows that must be in the local in-memory shuffle
          buffer in order to yield a batch. When there are no more rows to add to
          the buffer, the remaining rows in the buffer will be drained.
      local_shuffle_seed: The seed to use for the local random shuffle.
  
  Returns:
      An iterable over record batches.
docstr_tok: ["Return","a","batched","iterable","over","the","dataset",".","Examples",":",">",">",">","import","ray",">",">",">","for","batch","in","ray.data.range","(","...","1000000","...",")",".iterator","(",")",".iter_batches","(",")",":","#","doctest",":","+SKIP","...","print","(","batch",")","#","doctest",":","+SKIP","Time","complexity",":","O","(","1",")","Args",":","prefetch_batches",":","The","number","of","batches","to","fetch","ahead","of","the","current","batch","to","fetch",".","If","set","to","greater","than","0",",","a","separate","threadpool","will","be","used","to","fetch","the","objects","to","the","local","node",",","format","the","batches",",","and","apply","the","collate_fn",".","Defaults","to","1.","batch_size",":","The","number","of","rows","in","each","batch",",","or","None","to","use","entire","blocks","as","batches","(","blocks","may","contain","different","number","of","rows",")",".","The","final","batch","may","include","fewer","than","``","batch_size","``","rows","if","``","drop_last","``","is","``","False","``",".","Defaults","to","256.","batch_format",":","Specify","``","``","default","''","``","to","use","the","default","block","format","(","NumPy",")",",","``","``","pandas","''","``","to","select","``","pandas.DataFrame","``",",","``","pyarrow","''","to","select","``","pyarrow.Table","``",",","or","``","``","numpy","''","``","to","select","``","Dict","[","str",",","numpy.ndarray","]","``",",","or","None","to","return","the","underlying","block","exactly","as","is","with","no","additional","formatting",".","drop_last",":","Whether","to","drop","the","last","batch","if","it","'s","incomplete",".","local_shuffle_buffer_size",":","If","non-None",",","the","data","will","be","randomly","shuffled","using","a","local","in-memory","shuffle","buffer",",","and","this","value","will","serve","as","the","minimum","number","of","rows","that","must","be","in","the","local","in-memory","shuffle","buffer","in","order","to","yield","a","batch",".","When","there","are","no","more","rows","to","add","to","the","buffer",",","the","remaining","rows","in","the","buffer","will","be","drained",".","local_shuffle_seed",":","The","seed","to","use","for","the","local","random","shuffle",".","Returns",":","An","iterable","over","record","batches","."]
code: def iter_batches(
      self,
      *,
      prefetch_batches: int = 1,
      batch_size: int = 256,
      batch_format: Optional[str] = "default",
      drop_last: bool = False,
      local_shuffle_buffer_size: Optional[int] = None,
      local_shuffle_seed: Optional[int] = None,
      _collate_fn: Optional[
          Callable[[DataBatch], "CollatedData"]
      ] = None,
      _finalize_fn: Optional[Callable[[Any], Any]] = None,
      # Deprecated.
      prefetch_blocks: int = 0,
  ) -> Iterable[DataBatch]:
      """Return a batched iterable over the dataset.
  
      Examples:
          >>> import ray
          >>> for batch in ray.data.range(
          ...     1000000
          ... ).iterator().iter_batches(): # doctest: +SKIP
          ...     print(batch) # doctest: +SKIP
  
      Time complexity: O(1)
  
      Args:
          prefetch_batches: The number of batches to fetch ahead of the current batch
              to fetch. If set to greater than 0, a separate threadpool will be used
              to fetch the objects to the local node, format the batches, and apply
              the collate_fn. Defaults to 1.
          batch_size: The number of rows in each batch, or None to use entire blocks
              as batches (blocks may contain different number of rows).
              The final batch may include fewer than ``batch_size`` rows if
              ``drop_last`` is ``False``. Defaults to 256.
          batch_format: Specify ``"default"`` to use the default block format
              (NumPy), ``"pandas"`` to select ``pandas.DataFrame``, "pyarrow" to
              select ``pyarrow.Table``, or ``"numpy"`` to select
              ``Dict[str, numpy.ndarray]``, or None to return the underlying block
              exactly as is with no additional formatting.
          drop_last: Whether to drop the last batch if it's incomplete.
          local_shuffle_buffer_size: If non-None, the data will be randomly shuffled
              using a local in-memory shuffle buffer, and this value will serve as the
              minimum number of rows that must be in the local in-memory shuffle
              buffer in order to yield a batch. When there are no more rows to add to
              the buffer, the remaining rows in the buffer will be drained.
          local_shuffle_seed: The seed to use for the local random shuffle.
  
      Returns:
          An iterable over record batches.
      """
  
      if prefetch_blocks > 0:
          raise DeprecationWarning(
              "`prefetch_blocks` arg is deprecated in Ray 2.4. Use "
              "the `prefetch_batches` arg instead to specify the amount of "
              "prefetching in terms of batches instead of blocks."
          )
  
      batch_format = _apply_strict_mode_batch_format(batch_format)
  
      def _create_iterator() -> Iterator[DataBatch]:
          time_start = time.perf_counter()
          # Iterate through the dataset from the start each time
          # _iterator_gen is called.
          # This allows multiple iterations of the dataset without
          # needing to explicitly call `iter_batches()` multiple times.
          (
              block_iterator,
              stats,
              blocks_owned_by_consumer,
          ) = self._to_block_iterator()
  
          iterator = iter(
              iter_batches(
                  block_iterator,
                  stats=stats,
                  clear_block_after_read=blocks_owned_by_consumer,
                  batch_size=batch_size,
                  batch_format=batch_format,
                  drop_last=drop_last,
                  collate_fn=_collate_fn,
                  finalize_fn=_finalize_fn,
                  shuffle_buffer_min_size=local_shuffle_buffer_size,
                  shuffle_seed=local_shuffle_seed,
                  prefetch_batches=prefetch_batches,
              )
          )
  
          dataset_tag = self._get_dataset_tag()
          for batch in iterator:
              yield batch
              StatsManager.update_iteration_metrics(stats, dataset_tag)
          StatsManager.clear_iteration_metrics(dataset_tag)
  
          if stats:
              stats.iter_total_s.add(time.perf_counter() - time_start)
  
      return _IterableFromIterator(_create_iterator)
  
imports: import abc
  import time
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, TypeVar, Union
  import numpy
  from ray.data._internal.block_batching.iter_batches import iter_batches
  from ray.data._internal.stats import DatasetStats, StatsManager
  from ray.data.block import Block, BlockAccessor, BlockMetadata, DataBatch, _apply_strict_mode_batch_format
  from ray.types import ObjectRef
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 2 for calling the DataIterator obj's underlying member method code with example usage: obj.iter_batches() and returns: _IterableFromIterator