code: def into_arrow_batches(dataset, batch_size=1024, flatten_arrays=True):
      stream = iter(dataset)
      # peek 1
      first = next(stream)
      # re-assemble
      stream = chain([first], stream)
  
      encoder = ArrowEncoder.infer(first, flatten_arrays=flatten_arrays)
      encoded = map(encoder.encode, stream)
  
      row_batches = batcher(encoded, batch_size)
      column_batches = map(rows_to_columns, row_batches)
  
      for batch in column_batches:
          yield pa.record_batch(
              list(batch.values()), names=list(batch.keys())
          )
  
imports: from dataclasses import dataclass, field
  from functools import partial, singledispatch
  from itertools import chain
  from pathlib import Path
  from typing import List, Set, Optional, Union
  from typing_extensions import Literal
  from toolz.curried import keyfilter, valmap
  import numpy
  import pandas
  import pyarrow
  import pyarrow.parquet
  from gluonts.dataset import Dataset, DatasetWriter
  from gluonts.itertools import batcher, rows_to_columns
label_desc: Use image node_id 1 for calling a global function with example usage: into_arrow_batches(dataset, batch_size, flatten_arrays) without return types