[go: nahoru, domu]

Skip to content

Commit

Permalink
[NumPy] Remove references to deprecated NumPy type aliases.
Browse files Browse the repository at this point in the history
This change replaces references to a number of deprecated NumPy type aliases (np.bool, np.int, np.float, np.complex, np.object, np.str) with their recommended replacement (bool, int, float, complex, object, str).

NumPy 1.24 drops the deprecated aliases, so we must remove uses before updating NumPy.

PiperOrigin-RevId: 496908874
Change-Id: I7ee2af3bc548c4bbe6069defc3f3d143ba7eb88a
  • Loading branch information
hawkinsp authored and Copybara-Service committed Dec 21, 2022
1 parent d42b3cc commit 0f33452
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tf_agents/agents/ppo/ppo_policy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def splitter_fn(observation_and_mask):
clip=False)

# Take a step.
mask = np.array([True, False, True, False, True], dtype=np.bool)
mask = np.array([True, False, True, False, True], dtype=bool)
self.assertLen(mask, num_categories)
time_step = ts.TimeStep(
step_type=tf.constant([1], dtype=tf.int32),
Expand Down
2 changes: 1 addition & 1 deletion tf_agents/bandits/environments/dataset_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def mushroom_reward_distribution(r_noeat, r_eat_safe, r_eat_poison_bad,

def convert_covertype_dataset(file_path, buffer_size=40000):
with tf.io.gfile.GFile(file_path, 'r') as infile:
data_array = np.genfromtxt(infile, dtype=np.int, delimiter=',')
data_array = np.genfromtxt(infile, dtype=int, delimiter=',')
contexts = data_array[:, :-1]
context_tensor = tf.cast(contexts, tf.float32)
labels = data_array[:, -1] - 1 # Classes are from [1, 7].
Expand Down
4 changes: 2 additions & 2 deletions tf_agents/bandits/environments/ranking_environment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _item_sampling_fn():
return np.random.randint(-2, 3, [item_dim])

scores_weight_matrix = (np.reshape(
np.arange(global_dim * item_dim, dtype=np.float),
np.arange(global_dim * item_dim, dtype=float),
newshape=[item_dim, global_dim]) - 10) / 5

env = ranking_environment.RankingPyEnvironment(
Expand Down Expand Up @@ -127,7 +127,7 @@ def _global_sampling_fn():
def _item_sampling_fn():
return np.random.randint(-2, 3, [item_dim])
scores_weight_matrix = (np.reshape(
np.arange(global_dim * item_dim, dtype=np.float),
np.arange(global_dim * item_dim, dtype=float),
newshape=[item_dim, global_dim]) - 10) / 5
env = ranking_environment.RankingPyEnvironment(
_global_sampling_fn,
Expand Down
24 changes: 12 additions & 12 deletions tf_agents/environments/gym_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ def test_spec_from_gym_space_multi_discrete(self):

self.assertEqual((4,), spec.shape)
self.assertEqual(np.int32, spec.dtype)
np.testing.assert_array_equal(np.array([0], dtype=np.int), spec.minimum)
np.testing.assert_array_equal(np.array([0], dtype=int), spec.minimum)
np.testing.assert_array_equal(
np.array([0, 1, 2, 3], dtype=np.int), spec.maximum)
np.array([0, 1, 2, 3], dtype=int), spec.maximum)

def test_spec_from_gym_space_multi_binary(self):
multi_binary_space = gym.spaces.MultiBinary(4)
spec = gym_wrapper.spec_from_gym_space(multi_binary_space)

self.assertEqual((4,), spec.shape)
self.assertEqual(np.int32, spec.dtype)
np.testing.assert_array_equal(np.array([0], dtype=np.int), spec.minimum)
np.testing.assert_array_equal(np.array([1], dtype=np.int), spec.maximum)
np.testing.assert_array_equal(np.array([0], dtype=int), spec.minimum)
np.testing.assert_array_equal(np.array([1], dtype=int), spec.maximum)

def test_spec_from_gym_space_multi_binary_2d(self):
multi_binary_space = gym.spaces.MultiBinary((8, 8))
spec = gym_wrapper.spec_from_gym_space(multi_binary_space)

self.assertEqual((8, 8), spec.shape)
self.assertEqual(np.int32, spec.dtype)
np.testing.assert_array_equal(np.array([0], dtype=np.int), spec.minimum)
np.testing.assert_array_equal(np.array([1], dtype=np.int), spec.maximum)
np.testing.assert_array_equal(np.array([0], dtype=int), spec.minimum)
np.testing.assert_array_equal(np.array([1], dtype=int), spec.maximum)

def test_spec_from_gym_space_box_scalars(self):
for dtype in (np.float32, np.float64):
Expand All @@ -84,8 +84,8 @@ def test_spec_from_gym_space_box_scalars_simplify_bounds(self):

self.assertEqual((3, 4), spec.shape)
self.assertEqual(np.float32, spec.dtype)
np.testing.assert_array_equal(np.array([-1], dtype=np.int), spec.minimum)
np.testing.assert_array_equal(np.array([1], dtype=np.int), spec.maximum)
np.testing.assert_array_equal(np.array([-1], dtype=int), spec.minimum)
np.testing.assert_array_equal(np.array([1], dtype=int), spec.maximum)

def test_spec_from_gym_space_when_simplify_box_bounds_false(self):
# testing on gym.spaces.Dict which makes recursive calls to
Expand All @@ -101,13 +101,13 @@ def test_spec_from_gym_space_when_simplify_box_bounds_false(self):
self.assertEqual(np.float32, spec['box2'].dtype)
self.assertEqual('box1', spec['box1'].name)
self.assertEqual('box2', spec['box2'].name)
np.testing.assert_array_equal(np.array([-1, -1], dtype=np.int),
np.testing.assert_array_equal(np.array([-1, -1], dtype=int),
spec['box1'].minimum)
np.testing.assert_array_equal(np.array([1, 1], dtype=np.int),
np.testing.assert_array_equal(np.array([1, 1], dtype=int),
spec['box1'].maximum)
np.testing.assert_array_equal(np.array([-1, -1], dtype=np.int),
np.testing.assert_array_equal(np.array([-1, -1], dtype=int),
spec['box2'].minimum)
np.testing.assert_array_equal(np.array([1, 1], dtype=np.int),
np.testing.assert_array_equal(np.array([1, 1], dtype=int),
spec['box2'].maximum)

def test_spec_from_gym_space_box_array(self):
Expand Down
2 changes: 1 addition & 1 deletion tf_agents/typing/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
NestedSpecTensorOrArray = Union[NestedSpec, NestedTensor, NestedArray]

Int = Union[int, np.int16, np.int32, np.int64, Tensor, Array]
Bool = Union[bool, np.bool, Tensor, Array]
Bool = Union[bool, bool, Tensor, Array]

Float = Union[float, np.float16, np.float32, np.float64, Tensor, Array]
FloatOrReturningFloat = Union[Float, Callable[[], Float]]
Expand Down

0 comments on commit 0f33452

Please sign in to comment.