Skip to content

BUG: preserve top-level subarray dtypes in dtype_to_descr#31291

Open
wuxian08 wants to merge 5 commits intonumpy:mainfrom
wuxian08:fix-dtype-to-descr-subarray
Open

BUG: preserve top-level subarray dtypes in dtype_to_descr#31291
wuxian08 wants to merge 5 commits intonumpy:mainfrom
wuxian08:fix-dtype-to-descr-subarray

Conversation

@wuxian08
Copy link
Copy Markdown

This PR addresses #31280.

It makes two related changes in numpy.lib.format:

  • dtype_to_descr now preserves top-level subarray dtypes, so dtype_to_descr and descr_to_dtype round-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:

  • top-level and nested top-level subarray dtype roundtrips through dtype_to_descr / descr_to_dtype
  • open_memmap roundtrips for user-specified subarray dtypes

First 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.

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.

1 participant