Skip to content

Avoid deprecated ndarray shape assignment in named indexing - #550

Open
sylvesterkaczmarek wants to merge 3 commits into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/numpy-shape-assignment-deprecation
Open

Avoid deprecated ndarray shape assignment in named indexing#550
sylvesterkaczmarek wants to merge 3 commits into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/numpy-shape-assignment-deprecation

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #540.

NumPy 2.5 deprecates assigning directly to ndarray.shape. RegularNamedAxis.convert_key_item() currently rebuilds named index arrays as a flat integer array and restores their original dimensions with key_item.shape = original_shape, which triggers the deprecation warning for multidimensional named indices.

This change uses reshape(original_shape) instead. The converted index values and shape are unchanged, but no shape attribute is mutated.

The named-index tests now include focused coverage that a multidimensional array of element names preserves its original shape after conversion. The generic read/write test also uses reshape() instead of its own deprecated shape assignment, so the test suite does not retain the same NumPy 2.5 warning source.

Testing

Regression coverage verifies that a (2, 1) named index is converted to the expected integer indices while retaining its (2, 1) shape.

Signed-off-by: Sylvester Kaczmarek <assistant@SylvesterKaczmarek.com>
Signed-off-by: Sylvester Kaczmarek <assistant@SylvesterKaczmarek.com>
Signed-off-by: Sylvester Kaczmarek <assistant@SylvesterKaczmarek.com>
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