class_docstr: Writer object that saves experiences using Datasets.
class_docstr_tok: ["Writer","object","that","saves","experiences","using","Datasets","."]
code: def write(self, sample_batch: SampleBatchType):
      start = time.time()
  
      # Make sure columns like obs are compressed and writable.
      d = _to_json_dict(sample_batch, self.compress_columns)
      self.samples.append(d)
  
      # Todo: We should flush at the end of sampling even if this
      # condition was not reached.
      if len(self.samples) >= self.max_num_samples_per_file:
          ds = data.from_items(self.samples).repartition(
              num_blocks=1, shuffle=False
          )
          if self.format == "json":
              ds.write_json(self.path, try_create_dir=True)
          elif self.format == "parquet":
              ds.write_parquet(self.path, try_create_dir=True)
          else:
              raise ValueError("Unknown output type: ", self.format)
          self.samples = []
          logger.debug(
              "Wrote dataset in {}s".format(time.time() - start)
          )
  
file_path: ray/rllib/offline/dataset_writer.py
imports: import logging
  import os
  import time
  from ray import data
  from ray.rllib.offline.io_context import IOContext
  from ray.rllib.offline.json_writer import _to_json_dict
  from ray.rllib.offline.output_writer import OutputWriter
  from ray.rllib.utils.annotations import override, PublicAPI
  from ray.rllib.utils.typing import SampleBatchType
  from typing import Dict, List
label_desc: Use image node_id 2 for calling the DatasetWriter obj's underlying member method code with example usage: obj.write(sample_batch) without return types