Skip to content

Print the tuple-observation rejection as one sentence - #1306

Closed
DenisDrobyshev wants to merge 1 commit into
thu-ml:masterfrom
DenisDrobyshev:tuple-obs-error-message
Closed

DenisDrobyshev wants to merge 1 commit into
thu-ml:masterfrom
DenisDrobyshev:tuple-obs-error-message

Conversation

@DenisDrobyshev

Copy link
Copy Markdown

Description

Both places that reject a tuple observation split the message across two
positional arguments, so str(exception) renders the pair rather than the
sentence that was written:

env = DummyVectorEnv([TupleObsEnv])
env.reset()
TypeError: ('Tuple observation space is not supported. ', 'Please change it to array or dict space')

The trailing space on the first half shows the two were meant to be joined by
implicit concatenation; the comma between them defeated it. After:

TypeError: Tuple observation space is not supported. Please change it to array or dict space

The same two lines appear in tianshou/env/venvs.py (BaseVectorEnv.reset)
and tianshou/env/venv_wrappers.py (VectorEnvNormObs.reset), so both are
fixed and both are covered by the test.

An AST pass over tianshou/ finds no other built-in exception given more than
one positional argument.

Tests

test_tuple_obs_error_is_one_sentence in test/base/test_env.py, parametrised
over the plain vector env and the VectorEnvNormObs wrapper so each patched
file is exercised. len(exception.args) == 1 is the assertion that fails on
master; both cases pass here.

test/base/test_env.py -k "tuple_obs or norm_obs or env_obs" is 4 passed.
ruff format is clean on the three files. ruff check reports the same single
pre-existing PLW0108 at venvs.py:473 before and after this change, which is
untouched here.

Both raises split the message across two positional arguments, so
str(exception) rendered the pair rather than the sentence:

    TypeError: ('Tuple observation space is not supported. ', 'Please change
    it to array or dict space')

The trailing space on the first half shows the two were meant to be joined by
implicit concatenation, and the comma between them defeated it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ba90186c9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread test/base/test_env.py
"""
env: Any = DummyVectorEnv([_TupleObsEnv])
if wrap_norm_obs:
env = VectorEnvNormObs(env)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise the wrapper's own rejection path

When wrap_norm_obs is true, VectorEnvNormObs.reset() first calls the wrapped DummyVectorEnv.reset(), which raises from BaseVectorEnv.reset() before returning the tuple observation. Consequently, both parameter values exercise only the venvs.py change, and a regression in the newly patched VectorEnvNormObs exception would still pass this test. Use a stub vector environment whose reset() returns a tuple observation so the wrapper's own check is reached.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants