Skip to content

Reshape arrays rather than setting shape on them. - #548

Open
shubhxho wants to merge 1 commit into
google-deepmind:mainfrom
shubhxho:reshape-instead-of-setting-shape
Open

Reshape arrays rather than setting shape on them.#548
shubhxho wants to merge 1 commit into
google-deepmind:mainfrom
shubhxho:reshape-instead-of-setting-shape

Conversation

@shubhxho

@shubhxho shubhxho commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #540.

Problem

NumPy 2.5 deprecated assigning to ndarray.shape (release note, numpy#29536).

Axis.convert_key_item uses it on every named index built from a list or array of names, so ordinary named indexing emits a DeprecationWarning under NumPy >= 2.5. Two test helpers do the same.

With -W error::DeprecationWarning on NumPy 2.5.2 before the change:

8 failed, 678 passed

Fix

Use reshape instead. The semantics are the same at all three sites: the arrays are freshly built by np.array/np.arange and contiguous, so no copy is involved and no caller observes a difference.

Testing

$ python -W error::DeprecationWarning -m pytest dm_control/mujoco/index_test.py
686 passed

$ pytest dm_control/mjcf dm_control/mujoco
1741 passed, 11 skipped

The one unrelated failure on my machine, MujocoEngineTest::testRenderFlagOverridesAreNotPersistent, fails identically without this change (headless GL).

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 google-deepmind#540.

Signed-off-by: Shubh <shubh@shubhxho.com>
@google-cla

google-cla Bot commented Aug 15, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.

1 participant