From eaabbb1d0a5465a811caea03442ce50263ed500a Mon Sep 17 00:00:00 2001 From: Shubh Date: Sat, 15 Aug 2026 18:10:04 +0530 Subject: [PATCH] Reshape arrays rather than setting shape on them. NumPy 2.5 deprecated assigning to ndarray.shape. Every named index built from a list or array of names went through it, so ordinary indexing raised a DeprecationWarning. reshape does the same thing here - the arrays are freshly built and contiguous. Fixes #540. Signed-off-by: Shubh --- dm_control/mujoco/index.py | 2 +- dm_control/mujoco/index_test.py | 5 +++-- dm_control/mujoco/wrapper/core_test.py | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dm_control/mujoco/index.py b/dm_control/mujoco/index.py index 76e534cc..fa0492b6 100644 --- a/dm_control/mujoco/index.py +++ b/dm_control/mujoco/index.py @@ -378,7 +378,7 @@ def convert_key_item(self, key_item): key_item = np.array([self._names_to_offsets[util.to_native_string(k)] for k in key_item.flat]) # Ensure the output shape is the same as that of the input. - key_item.shape = original_shape + key_item = key_item.reshape(original_shape) return key_item diff --git a/dm_control/mujoco/index_test.py b/dm_control/mujoco/index_test.py index 3eaeae53..736943c8 100644 --- a/dm_control/mujoco/index_test.py +++ b/dm_control/mujoco/index_test.py @@ -347,8 +347,9 @@ def testReadWrite_(self, field): # Write unique values to the FieldIndexer and read them back again. # Don't write to non-float fields since these might contain pointers. if np.issubdtype(old_contents.dtype, np.floating): - new_contents = np.arange(old_contents.size, dtype=old_contents.dtype) - new_contents.shape = old_contents.shape + new_contents = np.arange( + old_contents.size, dtype=old_contents.dtype + ).reshape(old_contents.shape) field[:] = new_contents np.testing.assert_array_equal(new_contents, field[:]) diff --git a/dm_control/mujoco/wrapper/core_test.py b/dm_control/mujoco/wrapper/core_test.py index 3489f126..b78f8109 100644 --- a/dm_control/mujoco/wrapper/core_test.py +++ b/dm_control/mujoco/wrapper/core_test.py @@ -552,8 +552,9 @@ def _write_unique_values(self, attr_name, target_array): elif (attr_name != "stack" and not np.issubdtype(target_array.dtype, np.integer) and not np.issubdtype(target_array.dtype, np.bool_)): - new_contents = np.arange(target_array.size, dtype=target_array.dtype) - new_contents.shape = target_array.shape + new_contents = np.arange( + target_array.size, dtype=target_array.dtype + ).reshape(target_array.shape) target_array[:] = new_contents np.testing.assert_array_equal(new_contents, target_array[:])