class_docstr: Collects samples for one agent in one trajectory (episode).
  
  The agent may be part of a multi-agent environment. Samples are stored in
  lists including some possible automatic "shift" buffer at the beginning to
  be able to save memory when storing things like NEXT_OBS, PREV_REWARDS,
  etc.., which are specified using the trajectory view API.
class_docstr_tok: ["Collects","samples","for","one","agent","in","one","trajectory","(","episode",")",".","The","agent","may","be","part","of","a","multi-agent","environment",".","Samples","are","stored","in","lists","including","some","possible","automatic","``","shift","''","buffer","at","the","beginning","to","be","able","to","save","memory","when","storing","things","like","NEXT_OBS",",","PREV_REWARDS",",","etc","..",",","which","are","specified","using","the","trajectory","view","API","."]
docstr: Builds the buffers for sample collection, given an example data row.
  
  Args:
      single_row (Dict[str, TensorType]): A single row (keys=column
          names) of data to base the buffers on.
docstr_tok: ["Builds","the","buffers","for","sample","collection",",","given","an","example","data","row",".","Args",":","single_row","(","Dict","[","str",",","TensorType","]",")",":","A","single","row","(","keys=column","names",")","of","data","to","base","the","buffers","on","."]
code: def _build_buffers(self, single_row: Dict[str, TensorType]) -> None:
      """Builds the buffers for sample collection, given an example data row.
  
      Args:
          single_row (Dict[str, TensorType]): A single row (keys=column
              names) of data to base the buffers on.
      """
      for col, data in single_row.items():
          if col in self.buffers:
              continue
  
          shift = self.shift_before - (
              1
              if col
              in [
                  SampleBatch.OBS,
                  SampleBatch.INFOS,
                  SampleBatch.EPS_ID,
                  SampleBatch.AGENT_INDEX,
                  SampleBatch.ENV_ID,
                  SampleBatch.T,
                  SampleBatch.UNROLL_ID,
              ]
              else 0
          )
  
          # Store all data as flattened lists, except INFOS and state-out
          # lists. These are monolithic items (infos is a dict that
          # should not be further split, same for state-out items, which
          # could be custom dicts as well).
          should_flatten_action_key = (
              col == SampleBatch.ACTIONS
              and not self.disable_action_flattening
          )
          # Note (Artur) RL Modules's states need no flattening
          should_flatten_state_key = (
              col.startswith("state_out")
              and not self._enable_new_api_stack
          )
          if (
              col == SampleBatch.INFOS
              or should_flatten_state_key
              or should_flatten_action_key
          ):
              if should_flatten_action_key:
                  data = flatten_to_single_ndarray(data)
              self.buffers[col] = [[data for _ in range(shift)]]
          else:
              self.buffers[col] = [
                  [v for _ in range(shift)] for v in tree.flatten(data)
              ]
              # Store an example data struct so we know, how to unflatten
              # each data col.
              self.buffer_structs[col] = data
  
imports: import copy
  import logging
  import math
  from typing import Any, Dict, List, Optional
  import numpy
  import tree
  from gymnasium.spaces import Space
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy.view_requirement import ViewRequirement
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.spaces.space_utils import flatten_to_single_ndarray, get_dummy_batch_for_space
  from ray.rllib.utils.typing import EpisodeID, EnvID, TensorType, ViewRequirementsDict
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 9 for calling the AgentCollector obj's underlying member method code with example usage: obj._build_buffers(single_row) without return types