[Numpy-discussion] isbuiltin - failure of understanding

Matthew Brett matthew.brett@gmail....
Tue Feb 24 15:04:54 CST 2009


I was just trying to write a docstring for np.dtype.isbuiltin, when I
realized I didn't understand it.

As far as I can see, isbuitin should return:

0 for structured array dtypes
1 for types compiled into numpy
2 for extension types using the numpy C-API type extension machinery.

Here's the C code:

static PyObject *
arraydescr_isbuiltin_get(PyArray_Descr *self)
    long val;
    val = 0;
    if (self->fields == Py_None) val = 1;
    if (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;
    return PyInt_FromLong(val);

But, why is this?

In [2]: dt = np.dtype('S1')

In [3]: dt
Out[3]: dtype('|S1')

In [4]: dt.isbuiltin
Out[4]: 0

In [5]: print dt.fields

In [6]: print dt.fields == None

Same for np.dtype('U1')



More information about the Numpy-discussion mailing list