prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Bug in PixelObservationWrapper
  In the pixel_observation.py, we have a bit of code that looks like this: 
  
  ```
      def _add_pixel_observation(self, observation):
          if self._pixels_only:
              observation = collections.OrderedDict()
          elif self._observation_is_dict:
              observation = type(observation)(observation)
          else:
              observation = collections.OrderedDict()
              observation[STATE_KEY] = observation
  ```
  
  If you note, the argument `observation` is being clobbered in the else case, so now the observation dictionary at the STATE_KEY refers to itself instead of the underlying env's observation. 
  
  I'm happy to fix this and submit a pull request but I wanted to raise the community's attention to this first.  
  
  </issue>
  <code>
  [start of gym/wrappers/pixel_observation.py]
  1 """An observation wrapper that augments observations by pixel values."""
  2 
  3 import collections
  4 import copy
  5 
  6 import numpy as np
  7 
  8 from gym import spaces
  9 from gym import ObservationWrapper
  10 
  11 STATE_KEY = 'state'
  12 
  13 
  14 class PixelObservationWrapper(ObservationWrapper):
  15     """Augment observations by pixel values."""
  16 
  17     def __init__(self,
  18                  env,
  19                  pixels_only=True,
  20                  render_kwargs=None,
  21                  pixel_keys=('pixels', )):
  22         """Initializes a new pixel Wrapper.
  23 
  24         Args:
  25             env: The environment to wrap.
  26             pixels_only: If `True` (default), the original observation returned
  27                 by the wrapped environment will be discarded, and a dictionary
  28                 observation will only include pixels. If `False`, the
  29                 observation dictionary will contain both the original
  30                 observations and the pixel observations.
  31             render_kwargs: Optional `dict` containing keyword arguments passed
  32                 to the `self.render` method.
  33             pixel_keys: Optional custom string specifying the pixel
  34                 observation's key in the `OrderedDict` of observations.
  35                 Defaults to 'pixels'.
  36 
  37         Raises:
  38             ValueError: If `env`'s observation spec is not compatible with the
  39                 wrapper. Supported formats are a single array, or a dict of
  40                 arrays.
  41             ValueError: If `env`'s observation already contains any of the
  42                 specified `pixel_keys`.
  43         """
  44 
  45         super(PixelObservationWrapper, self).__init__(env)
  46 
  47         if render_kwargs is None:
  48             render_kwargs = {}
  49 
  50         for key in pixel_keys:
  51             render_kwargs.setdefault(key, {})
  52 
  53             render_mode = render_kwargs[key].pop('mode', 'rgb_array')
  54             assert render_mode == 'rgb_array', render_mode
  55             render_kwargs[key]['mode'] = 'rgb_array'
  56 
  57         wrapped_observation_space = env.observation_space
  58 
  59         if isinstance(wrapped_observation_space, spaces.Box):
  60             self._observation_is_dict = False
  61             invalid_keys = set([STATE_KEY])
  62         elif isinstance(wrapped_observation_space,
  63                         (spaces.Dict, collections.MutableMapping)):
  64             self._observation_is_dict = True
  65             invalid_keys = set(wrapped_observation_space.spaces.keys())
  66         else:
  67             raise ValueError("Unsupported observation space structure.")
  68 
  69         if not pixels_only:
  70             # Make sure that now keys in the `pixel_keys` overlap with
  71             # `observation_keys`
  72             overlapping_keys = set(pixel_keys) & set(invalid_keys)
  73             if overlapping_keys:
  74                 raise ValueError("Duplicate or reserved pixel keys {!r}."
  75                                  .format(overlapping_keys))
  76 
  77         if pixels_only:
  78             self.observation_space = spaces.Dict()
  79         elif self._observation_is_dict:
  80             self.observation_space = copy.deepcopy(wrapped_observation_space)
  81         else:
  82             self.observation_space = spaces.Dict()
  83             self.observation_space.spaces[STATE_KEY] = wrapped_observation_space
  84 
  85         # Extend observation space with pixels.
  86 
  87         pixels_spaces = {}
  88         for pixel_key in pixel_keys:
  89             pixels = self.env.render(**render_kwargs[pixel_key])
  90 
  91             if np.issubdtype(pixels.dtype, np.integer):
  92                 low, high = (0, 255)
  93             elif np.issubdtype(pixels.dtype, np.float):
  94                 low, high = (-float('inf'), float('inf'))
  95             else:
  96                 raise TypeError(pixels.dtype)
  97 
  98             pixels_space = spaces.Box(
  99                 shape=pixels.shape, low=low, high=high, dtype=pixels.dtype)
  100             pixels_spaces[pixel_key] = pixels_space
  101 
  102         self.observation_space.spaces.update(pixels_spaces)
  103 
  104         self._env = env
  105         self._pixels_only = pixels_only
  106         self._render_kwargs = render_kwargs
  107         self._pixel_keys = pixel_keys
  108 
  109     def observation(self, observation):
  110         pixel_observation = self._add_pixel_observation(observation)
  111         return pixel_observation
  112 
  113     def _add_pixel_observation(self, observation):
  114         if self._pixels_only:
  115             observation = collections.OrderedDict()
  116         elif self._observation_is_dict:
  117             observation = type(observation)(observation)
  118         else:
  119             observation = collections.OrderedDict()
  120             observation[STATE_KEY] = observation
  121 
  122         pixel_observations = {
  123             pixel_key: self.env.render(**self._render_kwargs[pixel_key])
  124             for pixel_key in self._pixel_keys
  125         }
  126 
  127         observation.update(pixel_observations)
  128 
  129         return observation
  130
  [end of gym/wrappers/pixel_observation.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/gym/wrappers/pixel_observation.py b/gym/wrappers/pixel_observation.py
  --- a/gym/wrappers/pixel_observation.py
  +++ b/gym/wrappers/pixel_observation.py
  @@ -110,14 +110,14 @@
           pixel_observation = self._add_pixel_observation(observation)
           return pixel_observation
   
  -    def _add_pixel_observation(self, observation):
  +    def _add_pixel_observation(self, wrapped_observation):
           if self._pixels_only:
               observation = collections.OrderedDict()
           elif self._observation_is_dict:
  -            observation = type(observation)(observation)
  +            observation = type(wrapped_observation)(wrapped_observation)
           else:
               observation = collections.OrderedDict()
  -            observation[STATE_KEY] = observation
  +            observation[STATE_KEY] = wrapped_observation
   
           pixel_observations = {
               pixel_key: self.env.render(**self._render_kwargs[pixel_key])
  
verification_info: {"golden_diff": "diff --git a/gym/wrappers/pixel_observation.py b/gym/wrappers/pixel_observation.py\n--- a/gym/wrappers/pixel_observation.py\n+++ b/gym/wrappers/pixel_observation.py\n@@ -110,14 +110,14 @@\n         pixel_observation = self._add_pixel_observation(observation)\n         return pixel_observation\n \n-    def _add_pixel_observation(self, observation):\n+    def _add_pixel_observation(self, wrapped_observation):\n         if self._pixels_only:\n             observation = collections.OrderedDict()\n         elif self._observation_is_dict:\n-            observation = type(observation)(observation)\n+            observation = type(wrapped_observation)(wrapped_observation)\n         else:\n             observation = collections.OrderedDict()\n-            observation[STATE_KEY] = observation\n+            observation[STATE_KEY] = wrapped_observation\n \n         pixel_observations = {\n             pixel_key: self.env.render(**self._render_kwargs[pixel_key])\n", "issue": "Bug in PixelObservationWrapper\nIn the pixel_observation.py, we have a bit of code that looks like this: \r\n\r\n```\r\n    def _add_pixel_observation(self, observation):\r\n        if self._pixels_only:\r\n            observation = collections.OrderedDict()\r\n        elif self._observation_is_dict:\r\n            observation = type(observation)(observation)\r\n        else:\r\n            observation = collections.OrderedDict()\r\n            observation[STATE_KEY] = observation\r\n```\r\n\r\nIf you note, the argument `observation` is being clobbered in the else case, so now the observation dictionary at the STATE_KEY refers to itself instead of the underlying env's observation. \r\n\r\nI'm happy to fix this and submit a pull request but I wanted to raise the community's attention to this first.  \n", "before_files": [{"content": "\"\"\"An observation wrapper that augments observations by pixel values.\"\"\"\n\nimport collections\nimport copy\n\nimport numpy as np\n\nfrom gym import spaces\nfrom gym import ObservationWrapper\n\nSTATE_KEY = 'state'\n\n\nclass PixelObservationWrapper(ObservationWrapper):\n    \"\"\"Augment observations by pixel values.\"\"\"\n\n    def __init__(self,\n                 env,\n                 pixels_only=True,\n                 render_kwargs=None,\n                 pixel_keys=('pixels', )):\n        \"\"\"Initializes a new pixel Wrapper.\n\n        Args:\n            env: The environment to wrap.\n            pixels_only: If `True` (default), the original observation returned\n                by the wrapped environment will be discarded, and a dictionary\n                observation will only include pixels. If `False`, the\n                observation dictionary will contain both the original\n                observations and the pixel observations.\n            render_kwargs: Optional `dict` containing keyword arguments passed\n                to the `self.render` method.\n            pixel_keys: Optional custom string specifying the pixel\n                observation's key in the `OrderedDict` of observations.\n                Defaults to 'pixels'.\n\n        Raises:\n            ValueError: If `env`'s observation spec is not compatible with the\n                wrapper. Supported formats are a single array, or a dict of\n                arrays.\n            ValueError: If `env`'s observation already contains any of the\n                specified `pixel_keys`.\n        \"\"\"\n\n        super(PixelObservationWrapper, self).__init__(env)\n\n        if render_kwargs is None:\n            render_kwargs = {}\n\n        for key in pixel_keys:\n            render_kwargs.setdefault(key, {})\n\n            render_mode = render_kwargs[key].pop('mode', 'rgb_array')\n            assert render_mode == 'rgb_array', render_mode\n            render_kwargs[key]['mode'] = 'rgb_array'\n\n        wrapped_observation_space = env.observation_space\n\n        if isinstance(wrapped_observation_space, spaces.Box):\n            self._observation_is_dict = False\n            invalid_keys = set([STATE_KEY])\n        elif isinstance(wrapped_observation_space,\n                        (spaces.Dict, collections.MutableMapping)):\n            self._observation_is_dict = True\n            invalid_keys = set(wrapped_observation_space.spaces.keys())\n        else:\n            raise ValueError(\"Unsupported observation space structure.\")\n\n        if not pixels_only:\n            # Make sure that now keys in the `pixel_keys` overlap with\n            # `observation_keys`\n            overlapping_keys = set(pixel_keys) & set(invalid_keys)\n            if overlapping_keys:\n                raise ValueError(\"Duplicate or reserved pixel keys {!r}.\"\n                                 .format(overlapping_keys))\n\n        if pixels_only:\n            self.observation_space = spaces.Dict()\n        elif self._observation_is_dict:\n            self.observation_space = copy.deepcopy(wrapped_observation_space)\n        else:\n            self.observation_space = spaces.Dict()\n            self.observation_space.spaces[STATE_KEY] = wrapped_observation_space\n\n        # Extend observation space with pixels.\n\n        pixels_spaces = {}\n        for pixel_key in pixel_keys:\n            pixels = self.env.render(**render_kwargs[pixel_key])\n\n            if np.issubdtype(pixels.dtype, np.integer):\n                low, high = (0, 255)\n            elif np.issubdtype(pixels.dtype, np.float):\n                low, high = (-float('inf'), float('inf'))\n            else:\n                raise TypeError(pixels.dtype)\n\n            pixels_space = spaces.Box(\n                shape=pixels.shape, low=low, high=high, dtype=pixels.dtype)\n            pixels_spaces[pixel_key] = pixels_space\n\n        self.observation_space.spaces.update(pixels_spaces)\n\n        self._env = env\n        self._pixels_only = pixels_only\n        self._render_kwargs = render_kwargs\n        self._pixel_keys = pixel_keys\n\n    def observation(self, observation):\n        pixel_observation = self._add_pixel_observation(observation)\n        return pixel_observation\n\n    def _add_pixel_observation(self, observation):\n        if self._pixels_only:\n            observation = collections.OrderedDict()\n        elif self._observation_is_dict:\n            observation = type(observation)(observation)\n        else:\n            observation = collections.OrderedDict()\n            observation[STATE_KEY] = observation\n\n        pixel_observations = {\n            pixel_key: self.env.render(**self._render_kwargs[pixel_key])\n            for pixel_key in self._pixel_keys\n        }\n\n        observation.update(pixel_observations)\n\n        return observation\n", "path": "gym/wrappers/pixel_observation.py"}]}