Skip to content

Commit

Permalink
Replace np.bool8 with np.bool_ for numpy 1.24 (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudo-rnd-thoughts authored Dec 19, 2022
1 parent 3a4234c commit d71a135
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gymnasium/utils/passive_env_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,19 @@ def env_step_passive_checker(env, action):
)
obs, reward, done, info = result

if not isinstance(done, (bool, np.bool8)):
if not isinstance(done, (bool, np.bool_)):
logger.warn(
f"Expects `done` signal to be a boolean, actual type: {type(done)}"
)
elif len(result) == 5:
obs, reward, terminated, truncated, info = result

# np.bool is actual python bool not np boolean type, therefore bool_ or bool8
if not isinstance(terminated, (bool, np.bool8)):
if not isinstance(terminated, (bool, np.bool_)):
logger.warn(
f"Expects `terminated` signal to be a boolean, actual type: {type(terminated)}"
)
if not isinstance(truncated, (bool, np.bool8)):
if not isinstance(truncated, (bool, np.bool_)):
logger.warn(
f"Expects `truncated` signal to be a boolean, actual type: {type(truncated)}"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/spaces/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_shape_inference(box, expected_shape):
(np.inf, True),
(np.nan, True), # This is a weird case that we allow
(True, False),
(np.bool8(True), False),
(np.bool_(True), False),
(1 + 1j, False),
(np.complex128(1 + 1j), False),
("string", False),
Expand Down
6 changes: 5 additions & 1 deletion tests/spaces/test_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ def test_sample_contains(space):
assert space.contains(sample)

for other_space in TESTING_SPACES:
assert isinstance(space.contains(other_space.sample()), bool)
sample = other_space.sample()
space_contains = other_space.contains(sample)
assert isinstance(
space_contains, bool
), f"{space_contains}, {type(space_contains)}, {space}, {other_space}, {sample}"


@pytest.mark.parametrize("space", TESTING_SPACES, ids=TESTING_SPACES_IDS)
Expand Down

0 comments on commit d71a135

Please # to comment.