From 2f62012cb0b298e9776d4b13d14754c800b8ae47 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Sun, 16 Aug 2026 10:16:37 +0100 Subject: [PATCH 1/3] Avoid deprecated ndarray shape assignment Signed-off-by: Sylvester Kaczmarek --- dm_control/mujoco/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dm_control/mujoco/index.py b/dm_control/mujoco/index.py index 76e534cc..81c2c93a 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 @@ -468,7 +468,7 @@ def __init__(self, parent_struct, field_name, axis_indexers): - """Initializes a new `FieldIndexer`. + """Initializes a new `FieldIndexer` instance. Args: parent_struct: Wrapped ctypes structure, as generated by `mjbindings`. From 44a0b3583ba31f23e2537889c5ec622a294465ac Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Sun, 16 Aug 2026 10:17:40 +0100 Subject: [PATCH 2/3] Test named indexing without ndarray shape mutation Signed-off-by: Sylvester Kaczmarek --- dm_control/mujoco/index_test.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dm_control/mujoco/index_test.py b/dm_control/mujoco/index_test.py index 3eaeae53..21e0e600 100644 --- a/dm_control/mujoco/index_test.py +++ b/dm_control/mujoco/index_test.py @@ -87,6 +87,15 @@ def assertIndexExpressionEqual(self, expected, actual): self.fail('Indexing expressions are not equal.\n' 'expected: {!r}\nactual: {!r}'.format(expected, actual)) + def testRegularNamedAxisPreservesMultidimensionalShape(self): + axis = index.RegularNamedAxis(['first', 'second']) + key = np.array([['second'], ['first']]) + + converted = axis.convert_key_item(key) + + np.testing.assert_array_equal(converted, [[1], [0]]) + self.assertEqual(converted.shape, key.shape) + @parameterized.parameters( # (field name, named index key, expected integer index key) ('actuator_gear', 'slide', 0), @@ -347,8 +356,8 @@ 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[:]) From 48c9ae5807bca14b6867ee2788ea9a0a2fdf968b Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Sun, 16 Aug 2026 11:25:01 +0100 Subject: [PATCH 3/3] chore: keep NumPy deprecation fix scoped Signed-off-by: Sylvester Kaczmarek --- dm_control/mujoco/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm_control/mujoco/index.py b/dm_control/mujoco/index.py index 81c2c93a..fa0492b6 100644 --- a/dm_control/mujoco/index.py +++ b/dm_control/mujoco/index.py @@ -468,7 +468,7 @@ def __init__(self, parent_struct, field_name, axis_indexers): - """Initializes a new `FieldIndexer` instance. + """Initializes a new `FieldIndexer`. Args: parent_struct: Wrapped ctypes structure, as generated by `mjbindings`.