class_docstr: Base wrapper implementing PyEnvironmentBaseWrapper interface for Gym envs.
  
  Action and observation specs are automatically generated from the action and
  observation spaces. See base class for py_environment.Base details.
class_docstr_tok: ["Base","wrapper","implementing","PyEnvironmentBaseWrapper","interface","for","Gym","envs",".","Action","and","observation","specs","are","automatically","generated","from","the","action","and","observation","spaces",".","See","base","class","for","py_environment.Base","details","."]
docstr: Make sure observation matches the specified space.
  
  Observation spaces in gym didn't have a dtype for a long time. Now that they
  do there is a large number of environments that do not follow the dtype in
  the space definition. Since we use the space definition to create the
  tensorflow graph we need to make sure observations match the expected
  dtypes.
  
  Args:
    observation: Observation to match the dtype on.
  
  Returns:
    The observation with a dtype matching the observation spec.
docstr_tok: ["Make","sure","observation","matches","the","specified","space",".","Observation","spaces","in","gym","did","n't","have","a","dtype","for","a","long","time",".","Now","that","they","do","there","is","a","large","number","of","environments","that","do","not","follow","the","dtype","in","the","space","definition",".","Since","we","use","the","space","definition","to","create","the","tensorflow","graph","we","need","to","make","sure","observations","match","the","expected","dtypes",".","Args",":","observation",":","Observation","to","match","the","dtype","on",".","Returns",":","The","observation","with","a","dtype","matching","the","observation","spec","."]
code: def _to_obs_space_dtype(self, observation):
      """Make sure observation matches the specified space.
  
      Observation spaces in gym didn't have a dtype for a long time. Now that they
      do there is a large number of environments that do not follow the dtype in
      the space definition. Since we use the space definition to create the
      tensorflow graph we need to make sure observations match the expected
      dtypes.
  
      Args:
        observation: Observation to match the dtype on.
  
      Returns:
        The observation with a dtype matching the observation spec.
      """
      # Make sure we handle cases where observations are provided as a list.
      flat_obs = nest.flatten_up_to(self._observation_spec, observation)
  
      matched_observations = []
      for spec, obs in zip(self._flat_obs_spec, flat_obs):
          matched_observations.append(np.asarray(obs, dtype=spec.dtype))
      return tf.nest.pack_sequence_as(
          self._observation_spec, matched_observations
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import Any, Dict, Optional, Text
  import gym
  import gym.spaces
  import numpy
  import tensorflow
  from tf_agents import specs
  from tf_agents.environments import py_environment
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tensorflow.python.util import nest
label_desc: Use image node_id 8 for calling the GymWrapper obj's underlying member method code with example usage: obj._to_obs_space_dtype(observation) and returns: tf