[Numpy-discussion] isbuiltin - failure of understanding
Tue Feb 24 15:10:11 CST 2009
On Tue, Feb 24, 2009 at 15:04, Matthew Brett <firstname.lastname@example.org> wrote:
> 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 : dt = np.dtype('S1')
> In : dt
> Out: dtype('|S1')
> In : dt.isbuiltin
> Out: 0
> In : print dt.fields
> In : print dt.fields == None
> Same for np.dtype('U1')
The variable-length string dtypes are not builtin. The user-defined
lengths make them user-defined dtypes.
If you want a real kick in the pants, try playing with dtype(str). And
then try eval'ing its repr.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion