[Numpy-discussion] type and kind for custom dtypes

Alex Samuel alex at alexsamuel.net
Sun May 5 10:58:13 EDT 2019


I'm working on building a number of related custom dtypes, and I'm not sure how to set the type and kind fields in PyArray_Descr.  I tried using type='V' and choosing a single unused kind for all my dtypes; this mostly worked, except I found that coercions would sometimes treat values of two different dtypes as if they were the same.  But not always... sometimes my registered cast functions would be called.

Through trial and error, I've found that if I choose an unused type code for each dtype, coercion seems to work as I expect it to (no coercion unless I've provided a cast).  The kind doesn't seem to matter.

I couldn't find any guidance in the docs for how to choose these values.  Apologies if I've overlooked something.  Could someone please advise me?

More widely, is there some global registry of these codes?  Is the number of NumPy dtypes limited to the number of (UTF-8-encodable) chars?  It seems like common practice to use dtype.kind in user code.  If I use one or more for my custom dtypes, is there any mechanism to ensure they do not collide with others'?  Are there any other semantics for either field I should take into account?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190505/d30721ff/attachment.html>

More information about the NumPy-Discussion mailing list