[Bug] in `env_checker.py`
🐛 Bug
When the observation_space is a Dict, only the keys in the observation_space.spaces.keys() are checked with the keys returned in the observation. If there is a key in the returned observation, which is not present in the observation_space.spaces.keys() then no error is thrown, which should not be the case ideally.
Code snippets from env_checker.py for your reference
# for reset
if isinstance(observation_space, spaces.Dict):
assert isinstance(obs, dict), "The observation returned by `reset()` must be a dictionary"
for key in observation_space.spaces.keys():
try:
_check_obs(obs[key], observation_space.spaces[key], "reset")
except AssertionError as e:
raise AssertionError(f"Error while checking key={key}: " + str(e)) from e
# for step
if isinstance(observation_space, spaces.Dict):
assert isinstance(obs, dict), "The observation returned by `step()` must be a dictionary"
for key in observation_space.spaces.keys():
try:
_check_obs(obs[key], observation_space.spaces[key], "step")
except AssertionError as e:
raise AssertionError(f"Error while checking key={key}: " + str(e)) from e
I'll work on fixing it, but wanted your approval before that
Hello, you are right (although in practice, sb3 will probably work in that case). We would welcome a PR that solves this issue ;)
Cool, will send a PR soon
Do I need to create a separate pytest for this or modify the test file for env_checker?
modify the test file for env_checker?
Please modify the test file for the env checker.