Skip to content

Conversation

@cjdoris
Copy link
Member

@cjdoris cjdoris commented Jan 23, 2026

That is, np.array(array).dtype == np.dtype(eltype(array)).

For this to hold, we needed to restrict to only creating dtypes for primitives, tuples and named tuples. We removed support for arbitrary structs (which are not supported by our implementation of the array interface and buffer protocol).

We also worked around a feature/bug/quirk of numpy in that if you do numpy.dtype(descr) where descr is a list of (name,type) field descriptors of a struct, then the dtype you get is not the same as the dtype of an array constructed from something whose array interface has that same descr. In particular, if any item in descr is struct padding like ("", "|V4"), then on conversion to a dtype the name is replaced with e.g. "f2". Going the array route, the padding gets ignored and does not feature in the resulting dtype. The fix here is to compute a different representation of the same information for the dtype - namely the dict of names, types and offsets way.

That is, np.array(array).dtype == np.dtype(eltype(array)).

For this to hold, we needed to restrict to only creating dtypes for
primitives, tuples and named tuples. We removed support for arbitrary
structs (which are not supported by our implementation of the array
interface and buffer protocol).

We also worked around a feature/bug/quirk of numpy in that if you do
numpy.dtype(descr) where descr is a list of (name,type) field
descriptors of a struct, then the dtype you get is not the same as the
dtype of an array constructed from something whose array interface has
that same descr. In particular, if any item in descr is struct padding
like ("", "|V4"), then on conversion to a dtype the name is replaced
with e.g. "f2". Going the array route, the padding gets ignored and
does not feature in the resulting dtype. The fix here is to compute a
different representation of the same information for the dtype - namely
the dict of names, types and offsets way.
@cjdoris
Copy link
Member Author

cjdoris commented Jan 23, 2026

Follow up to #738 and #737.

@cjdoris cjdoris merged commit ef6c404 into main Jan 23, 2026
16 checks passed
@cjdoris cjdoris deleted the dtype-and-array-interface-fixes branch January 23, 2026 21:56
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.

2 participants