[Numpy-discussion] Parameterised dtypes

Richard Hattersley rhattersley at gmail.com
Fri May 24 10:12:32 EDT 2013

Hi all,

I'm in the process of defining some new dtypes to handle non-physical
calendars (such as the 360-day calendar used in the climate modelling
world). This is all going fine[*] so far, but I'd like to know a little bit
more about how much is ultimately possible.

The PyArray_Descr members `metadata` and `c_metadata` allow run-time
parametrisation, but is it possible to hook into the dtype('...') parsing
mechanism to supply those parameters? Or is there some other dtype
mechanism for supplying parameters?

As an example, would it be possible to supply month lengths?
>>> a = np.zeros(n, dtype='my_date[34,33,31,30,30,29,29,30,31,32,34,35]')

Or is the intended use of parametrisation more like:
>>> weird = my_stuff.make_dtype([34,33,31,30,30,29,29,30,31,32,34,35])
>>> a = np.zeros(n, dtype=weird)

[*] The docs could do with updating, and the examples would benefit from
standardising (or at least explaining the significance of the differences).
I intend to post updates where possible.

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

More information about the NumPy-Discussion mailing list