BUG: preserve top-level subarray dtypes in dtype_to_descr#31291
Open
wuxian08 wants to merge 5 commits intonumpy:mainfrom
Open
BUG: preserve top-level subarray dtypes in dtype_to_descr#31291wuxian08 wants to merge 5 commits intonumpy:mainfrom
wuxian08 wants to merge 5 commits intonumpy:mainfrom
Conversation
added 5 commits
April 20, 2026 08:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses #31280.
It makes two related changes in numpy.lib.format:
dtype_to_descrnow preserves top-level subarray dtypes, sodtype_to_descranddescr_to_dtyperound-trip those dtypes correctly.open_memmap(..., mode='w+')now normalizes top-level subarray dtypes when writing .npy headers by recursively folding subarray dimensions into the array shape and writing the base dtype in descr.The tests were extended to cover:
dtype_to_descr/descr_to_dtypeopen_memmaproundtrips for user-specified subarray dtypesFirst time committer introduction
I am a C++ and Python developer, and we use NumPy heavily for data processing and for data exchange between C++ and Python (using pybind11). This issue came up while we were looking for a reliable way to serialize and deserialize NumPy dtypes.
AI Disclosure
I used Codex CLI during the preparation of this PR. It helped inspect the relevant NumPy code, suggest code changes and tests, and help me reason through edge cases. I reviewed the code myself, made additional changes manually, and I am submitting this PR myself.