code: def write_dataset(
      Writer,
      dataset,
      path,
      metadata=None,
      batch_size=1024,
      flatten_arrays=True,
  ):
      dataset = map(keyfilter(lambda key: key != "source"), dataset)
      dataset = map(valmap(_encode_py_to_arrow), dataset)
  
      batches = into_arrow_batches(
          dataset, batch_size, flatten_arrays=flatten_arrays
      )
      first = next(batches)
  
      schema = first.schema
  
      if metadata is not None:
          schema = schema.with_metadata(metadata)
  
      with open(path, "wb") as fobj:
          writer = Writer(fobj, schema=schema)
          for batch in chain([first], batches):
              writer.write_batch(batch)
  
          writer.close()
  
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 4 for calling a global function with example usage: write_dataset(Writer, dataset, path, metadata, batch_size, flatten_arrays) without return types