You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow coercion of Julia types to NumPy dtypes #737
Is your feature request related to a problem? Please describe.
We're using Julia types as dtypes, but a third-party library does np.dtype(jl_type). Maybe there's a way to support this as an upstream feature for everyone.
Describe the solution you'd like
Ideally, I'd like something like an implementation of the __numpy_dtype__ protocol or supported Julia types. This could even be implemented on some kinds of structs.
Describe alternatives you've considered
Maybe we could solve this upstream by converting back and forth, but a simple conversion is always helpful.
TIL about __numpy_dtype__, it looks like a recent addition. We could certainly implement it for Julia types (jl.Int64.__numpy_dtype__ being np.int64 etc).
It's OK I've done it (#738) - it was surprisingly simple because I could re-use existing type-conversion machinery from the array interface code. This means we can support struct types for free. It also means that doing np.dtype(eltype(julia_array)) should be consistent with np.array(julia_array).dtype in all cases.
Reacted by Hameer Abbasi, Ilan Gold and amalia-k510
Activity
cjdoris commentedon Jan 22, 2026
TIL about
__numpy_dtype__, it looks like a recent addition. We could certainly implement it for Julia types (jl.Int64.__numpy_dtype__beingnp.int64etc).hameerabbasi commentedon Jan 23, 2026
That'd be great! I'm not super well-versed in Julia; but if the relevant code is in Python, I'm happy to make a PR.
Also small correction:
jl.Int64.__numpy_dtype__()would benp.dtype(np.int64)This has two minor differences:
np.int64.cjdoris commentedon Jan 23, 2026
It's OK I've done it (#738) - it was surprisingly simple because I could re-use existing type-conversion machinery from the array interface code. This means we can support struct types for free. It also means that doing
np.dtype(eltype(julia_array))should be consistent withnp.array(julia_array).dtypein all cases.