docstr: Tests the `fill` argument of `get` with a lookback range >0.
docstr_tok: ["Tests","the","`","fill","`","argument","of","`","get","`","with","a","lookback","range",">","0","."]
code: def test_get_with_fill_and_neg_indices_into_lookback_buffer(self):
      """Tests the `fill` argument of `get` with a lookback range >0."""
      buffer = BufferWithInfiniteLookback(
          data=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          lookback=4,
          # Specify a space, so we can fill and one-hot discrete data properly.
          space=gym.spaces.Discrete(11),
      )
  
      # Test on ongoing and finalized buffer.
      for finalized in [False, True]:
          if finalized:
              buffer.finalize()
  
          self.assertTrue(len(buffer), 7)
  
          # Lokback buffer is [0, 1, 2, 3]
          # Individual indices with negative indices into lookback buffer.
          check(buffer.get(-1, neg_indices_left_of_zero=True), 3)
          check(buffer.get(-2, neg_indices_left_of_zero=True), 2)
          check(buffer.get(-3, neg_indices_left_of_zero=True), 1)
          check(buffer.get(-4, neg_indices_left_of_zero=True), 0)
          check(
              buffer.get([-1, -3], neg_indices_left_of_zero=True),
              [3, 1],
          )
          # Slices with negative indices into lookback buffer.
          check(
              buffer.get(slice(-2, -1), neg_indices_left_of_zero=True),
              [2],
          )
          check(
              buffer.get(slice(-2, 0), neg_indices_left_of_zero=True),
              [2, 3],
          )
          check(
              buffer.get(slice(-2, 4), neg_indices_left_of_zero=True),
              [2, 3, 4, 5, 6, 7],
          )
          check(
              buffer.get(
                  slice(-2, None), neg_indices_left_of_zero=True
              ),
              [2, 3, 4, 5, 6, 7, 8, 9, 10],
          )
          # With left fill.
          check(
              buffer.get(-8, fill=10, neg_indices_left_of_zero=True), 10
          )
          check(
              buffer.get(-800, fill=10, neg_indices_left_of_zero=True),
              10,
          )
          check(
              buffer.get(
                  [-8, -1], fill=9, neg_indices_left_of_zero=True
              ),
              [9, 3],
          )
          check(
              buffer.get(
                  slice(-8, 0), fill=10, neg_indices_left_of_zero=True
              ),
              [10, 10, 10, 10, 0, 1, 2, 3],
          )
          check(
              buffer.get(
                  slice(-7, 1), fill=10, neg_indices_left_of_zero=True
              ),
              [10, 10, 10, 0, 1, 2, 3, 4],
          )
          check(
              buffer.get(
                  slice(-6, None),
                  fill=11,
                  neg_indices_left_of_zero=True,
              ),
              [11, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          )
          check(
              buffer.get(
                  slice(-10, -4), fill=11, neg_indices_left_of_zero=True
              ),
              [11, 11, 11, 11, 11, 11],
          )
          # Both start stop on left side.
          check(
              buffer.get(
                  slice(-10, -9), fill=0, neg_indices_left_of_zero=True
              ),
              [0],
          )
          check(
              buffer.get(
                  slice(-20, -15), fill=0, neg_indices_left_of_zero=True
              ),
              [0, 0, 0, 0, 0],
          )
          check(
              buffer.get(
                  slice(-1001, -1000),
                  fill=6,
                  neg_indices_left_of_zero=True,
              ),
              [6],
          )
          # Both start stop on right side.
          check(
              buffer.get(
                  slice(10, 15), fill=0, neg_indices_left_of_zero=True
              ),
              [0, 0, 0, 0, 0],
          )
          check(
              buffer.get(
                  slice(15, 17), fill=0, neg_indices_left_of_zero=True
              ),
              [0, 0],
          )
          check(
              buffer.get(
                  slice(1000, 1001),
                  fill=6,
                  neg_indices_left_of_zero=True,
              ),
              [6],
          )
          # Right fill.
          check(
              buffer.get(8, fill=10, neg_indices_left_of_zero=True), 10
          )
          check(
              buffer.get(800, fill=10, neg_indices_left_of_zero=True),
              10,
          )
          check(
              buffer.get([8, 1], fill=9, neg_indices_left_of_zero=True),
              [9, 5],
          )
          check(
              buffer.get(
                  slice(-2, 8), fill=12, neg_indices_left_of_zero=True
              ),
              [2, 3, 4, 5, 6, 7, 8, 9, 10, 12],
          )
          check(
              buffer.get(
                  slice(-1, 9), fill=13, neg_indices_left_of_zero=True
              ),
              [3, 4, 5, 6, 7, 8, 9, 10, 13, 13],
          )
          check(
              buffer.get(
                  slice(-1, 5), fill=-14, neg_indices_left_of_zero=True
              ),
              [3, 4, 5, 6, 7, 8],
          )
          # No fill necessary (even though requested).
          check(
              buffer.get(
                  slice(-1, None),
                  fill=999,
                  neg_indices_left_of_zero=True,
              ),
              [3, 4, 5, 6, 7, 8, 9, 10],
          )
          check(
              buffer.get(
                  slice(-4, -1), fill=999, neg_indices_left_of_zero=True
              ),
              [0, 1, 2],
          )
          check(
              buffer.get(
                  slice(-1, 2), fill=999, neg_indices_left_of_zero=True
              ),
              [3, 4, 5],
          )
  
      # Check the type on the finalized buffer (numpy arrays).
      data = buffer.get(
          slice(-17, -15), fill=0, neg_indices_left_of_zero=True
      )
      self.assertTrue(isinstance(data, np.ndarray))
      check(data, [0, 0])
      data = buffer.get([-3, -1], fill=0, neg_indices_left_of_zero=True)
      self.assertTrue(isinstance(data, np.ndarray))
      check(data, [1, 3])
  
file_path: ray/rllib/env/tests/test_lookback_buffer.py
imports: import unittest
  import gymnasium
  import numpy
  from ray.rllib.env.utils import BufferWithInfiniteLookback
  from ray.rllib.utils.spaces.space_utils import batch, get_dummy_batch_for_space
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 6 for calling the TestBufferWithInfiniteLookback obj's underlying member method code with example usage: obj.test_get_with_fill_and_neg_indices_into_lookback_buffer() without return types