Replace np.bool8 with np.bool_ for numpy 1.24 (#221)

This commit is contained in:
Mark Towers
2022-12-19 12:53:06 +00:00
committed by GitHub
parent 3a4234c86c
commit d71a135882
3 changed files with 9 additions and 5 deletions

View File

@@ -238,7 +238,7 @@ 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)}"
)
@@ -246,11 +246,11 @@ def env_step_passive_checker(env, action):
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)}"
)

View File

@@ -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),

View File

@@ -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)