Repository navigation
Conversation
Add py::register_numpy_dtype<T>() and py::numpy_field_descriptor so a structured dtype can be registered from a list of field descriptors without py::detail. The fields can come from a layout-compatible type, which is necessary when the registered type has private members. Document PYBIND11_NUMPY_DTYPE_EX and PYBIND11_FIELD_DESCRIPTOR[_EX]. Assisted-by: ClaudeCode:claude-fable-5-2
henryiii
marked this pull request as ready for review
November 26, 2026 05:01
Collaborator
|
— codex on behalf of Ralf — No actionable findings. The public wrapper uses the same structured-dtype registration path as the macros, including layout and dtype validation. The test registers a wrapper with private members by supplying the field descriptors explicitly, then checks the renamed fields and the C++/Python round trip. All 21 focused NumPy dtype tests passed on regular and free-threaded CPython 3.14.10. Wrapper, Regression Generated by Codex. Ralf has yet to review these findings. |
This branch has not been deployed
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 is one I might need in boost-histogram; if we provide access via a helper, the stuff we need to register the dtype is not public API. This adds a public API for this missing gap.
🤖 AI text below 🤖
Description
PYBIND11_NUMPY_DTYPEandPYBIND11_NUMPY_DTYPE_EXread the fields of the registered type, so the fields must be accessible members of that type. A type that keeps its data in a private member (for example,boost::histogram::accumulators::meanin boostorg/histogram#323) can only be registered throughpy::detail::npy_format_descriptor<T>::register_dtypeandpy::detail::field_descriptor.This PR adds a public interface for that:
py::register_numpy_dtype<T>(fields)forwards to the existingregister_dtype.py::numpy_field_descriptoris an alias fordetail::field_descriptor.pybind11 does not check the field offsets against the registered type. The docs say this.
The docs now also describe
PYBIND11_NUMPY_DTYPE_EX,PYBIND11_FIELD_DESCRIPTOR, andPYBIND11_FIELD_DESCRIPTOR_EX, which were not documented.Suggested changelog entry:
py::register_numpy_dtype<T>()andpy::numpy_field_descriptorto register a structured NumPy dtype from a list of field descriptors, including fields from a layout-compatible type.