From 40049518c7e6a9012f3a592abf65479fde836dc9 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 11:12:22 +0100 Subject: [PATCH 1/7] ci: use correct gym compatibility in tests --- tests/test_gym.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_gym.py b/tests/test_gym.py index d75160c..9a6c47a 100644 --- a/tests/test_gym.py +++ b/tests/test_gym.py @@ -28,6 +28,12 @@ "`np.bool8` is a deprecated alias for `np.bool_`. (Deprecated NumPy 1.24)" ) +# Gym V26 introduced render_mode / the new step API; V21 uses the legacy API. +if openai_gym.__version__ >= "0.26": + GYM_COMPAT_ENV_ID = "GymV26Environment-v0" +else: + GYM_COMPAT_ENV_ID = "GymV21Environment-v0" + # We do not test Atari environment's here because we check all variants of Pong in test_envs.py (There are too many Atari environments) if openai_gym.__version__ >= "0.24.0": CLASSIC_CONTROL_ENVS = [ @@ -48,7 +54,7 @@ ) def test_gym_conversion_by_id(env_id): """Tests that the gym conversion works through specifying the env_id.""" - env = gymnasium.make("GymV26Environment-v0", env_id=env_id).unwrapped + env = gymnasium.make(GYM_COMPAT_ENV_ID, env_id=env_id).unwrapped with warnings.catch_warnings(record=True) as caught_warnings: check_env(env, skip_render_check=True) @@ -67,7 +73,7 @@ def test_gym_conversion_by_id(env_id): def test_gym_conversion_instantiated(env_id): """Tests that the gym conversion works with an instantiated gym environment.""" env = openai_gym.make(env_id) - env = gymnasium.make("GymV26Environment-v0", env=env).unwrapped + env = gymnasium.make(GYM_COMPAT_ENV_ID, env=env).unwrapped print("render-mode", env.render_mode) print("render-modes", env.metadata) @@ -88,8 +94,11 @@ class EnvWithData(openai_gym.Env): def __init__(self): """Initialises the environment with hidden data.""" - self.observation_space = openai_Box(low=0, high=1) - self.action_space = openai_Box(low=0, high=1) + # gym 0.21 requires an explicit shape when low/high are scalars. + self.observation_space = openai_Box(low=0, high=1, shape=()) + self.action_space = openai_Box(low=0, high=1, shape=()) + # Present so GymV26CompatibilityV0 can read it on gym<0.26 installs. + self.render_mode = None self.data = 123 From c5675989402ba4f793b930a18c0f277b5be60248 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 11:31:19 +0100 Subject: [PATCH 2/7] fix: correct seed return in gym v21 protocol --- shimmy/openai_gym_compatibility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shimmy/openai_gym_compatibility.py b/shimmy/openai_gym_compatibility.py index 0ffb225..5af21ee 100644 --- a/shimmy/openai_gym_compatibility.py +++ b/shimmy/openai_gym_compatibility.py @@ -3,7 +3,7 @@ # pyright: reportGeneralTypeIssues=false, reportPrivateImportUsage=false from __future__ import annotations -from typing import Any, Protocol, runtime_checkable +from typing import Any, List, Protocol, runtime_checkable import gymnasium from gymnasium import error @@ -152,7 +152,7 @@ def close(self): """Close the environment.""" ... - def seed(self, seed: int | None = None): + def seed(self, seed: int | None = None) -> List[int] | None: """Set the seed for this env's random number generator(s).""" ... From 3037f20d41fa9139846065248b233262e07cfe99 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 11:53:52 +0100 Subject: [PATCH 3/7] fix: call super().reset in gym v21 compatibility --- shimmy/openai_gym_compatibility.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shimmy/openai_gym_compatibility.py b/shimmy/openai_gym_compatibility.py index 5af21ee..6cddf07 100644 --- a/shimmy/openai_gym_compatibility.py +++ b/shimmy/openai_gym_compatibility.py @@ -223,6 +223,9 @@ def reset( Returns: (observation, info) """ + # Initialise Gymnasium's RNG (check_env / seeding API expect `_np_random`). + super().reset(seed=seed) + if seed is not None: self.gym_env.seed(seed) From 65df98b94799401a07e449021c9a4a292da55ec9 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 11:57:10 +0100 Subject: [PATCH 4/7] test: ignore seed function deprecation warning for gym v21 --- tests/test_gym.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_gym.py b/tests/test_gym.py index 9a6c47a..acd809d 100644 --- a/tests/test_gym.py +++ b/tests/test_gym.py @@ -22,6 +22,8 @@ "A Box observation space maximum value is infinity. This is probably too high.", "For Box action spaces, we recommend using a symmetric and normalized space (range=[-1, 1] or [0, 1]). See https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html for more information.", "The environment CartPole-v0 is out of date. You should consider upgrading to version `v1`.", + "Official support for the `seed` function is dropped. Standard practice is to reset gymnasium environments " + "using `env.reset(seed=)`", ] ] CHECK_ENV_IGNORE_WARNINGS.append( From 1c64318f79e2e292650687277474c60899e968dd Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 12:01:47 +0100 Subject: [PATCH 5/7] style: satisfy pyupgrade --- shimmy/openai_gym_compatibility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shimmy/openai_gym_compatibility.py b/shimmy/openai_gym_compatibility.py index 6cddf07..dacd579 100644 --- a/shimmy/openai_gym_compatibility.py +++ b/shimmy/openai_gym_compatibility.py @@ -3,7 +3,7 @@ # pyright: reportGeneralTypeIssues=false, reportPrivateImportUsage=false from __future__ import annotations -from typing import Any, List, Protocol, runtime_checkable +from typing import Any, Protocol, runtime_checkable import gymnasium from gymnasium import error @@ -152,7 +152,7 @@ def close(self): """Close the environment.""" ... - def seed(self, seed: int | None = None) -> List[int] | None: + def seed(self, seed: int | None = None) -> list[int] | None: """Set the seed for this env's random number generator(s).""" ... From c8f40da9500add2b6de60052fef2490fc981dd87 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 12:04:01 +0100 Subject: [PATCH 6/7] test: also ignore "not accept options as a reset parameter" warning --- tests/test_gym.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_gym.py b/tests/test_gym.py index acd809d..c369fb2 100644 --- a/tests/test_gym.py +++ b/tests/test_gym.py @@ -22,8 +22,10 @@ "A Box observation space maximum value is infinity. This is probably too high.", "For Box action spaces, we recommend using a symmetric and normalized space (range=[-1, 1] or [0, 1]). See https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html for more information.", "The environment CartPole-v0 is out of date. You should consider upgrading to version `v1`.", + # Gym v21 warnings "Official support for the `seed` function is dropped. Standard practice is to reset gymnasium environments " "using `env.reset(seed=)`", + "Gym v21 environment do not accept options as a reset parameter, options={}", ] ] CHECK_ENV_IGNORE_WARNINGS.append( From 68ff665f382ac29e90ecd794c224168d2d0cb99a Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 10 Jul 2026 12:23:02 +0100 Subject: [PATCH 7/7] test: ignore numpy shape assignment warnings for dm_control --- tests/test_dm_control.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_dm_control.py b/tests/test_dm_control.py index dff710e..e10a145 100644 --- a/tests/test_dm_control.py +++ b/tests/test_dm_control.py @@ -50,6 +50,10 @@ def test_dm_control_suite_envs(): ] ] CHECK_ENV_IGNORE_WARNINGS.append("`in1d` is deprecated. Use `np.isin` instead.") +CHECK_ENV_IGNORE_WARNINGS.append( + "Setting the shape on a NumPy array has been deprecated in NumPy 2.5.\n" + "As an alternative, you can create a new view using np.reshape (with copy=False if needed)." +) @pytest.mark.parametrize("env_id", DM_CONTROL_ENV_IDS)