diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-12-05 23:55:03 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-12-05 23:55:03 +0000 |
commit | 4772f10191f87a3446f4862de6d4b953e0dd95ff (patch) | |
tree | d67be2f2ba157fd51719b99cd8a6fb657d5f6649 /scipy/base/src/arrayobject.c | |
parent | 73eff17e359d08053183fc0aa4280261ca580dbd (diff) | |
download | numpy-4772f10191f87a3446f4862de6d4b953e0dd95ff.tar.gz |
Creating data-descriptors from a dictionary now works.
Diffstat (limited to 'scipy/base/src/arrayobject.c')
-rw-r--r-- | scipy/base/src/arrayobject.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index b9a5bbc08..739fd5a68 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -1719,6 +1719,28 @@ array_subscript(PyArrayObject *self, PyObject *op) } } + if (PyString_Check(op) || PyUnicode_Check(op)) { + if (self->descr->fields) { + PyObject *obj; + obj = PyDict_GetItem(self->descr->fields, op); + if (obj != NULL) { + PyArray_Descr *descr; + int offset; + PyObject *title; + + if (PyArg_ParseTuple(obj, "Oi|O", + &descr, &offset, &title)) + return PyArray_GetField(self, descr, + offset); + } + } + + PyErr_Format(PyExc_ValueError, + "field named %s not found.", + PyString_AsString(op)); + return NULL; + } + /* wrap arguments into a mapiter object */ mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op); if (mit == NULL) return NULL; @@ -1807,6 +1829,29 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) } + if (PyString_Check(index) || PyUnicode_Check(index)) { + if (self->descr->fields) { + PyObject *obj; + obj = PyDict_GetItem(self->descr->fields, index); + if (obj != NULL) { + PyArray_Descr *descr; + int offset; + PyObject *title; + + if (PyArg_ParseTuple(obj, "Oi|O", + &descr, &offset, &title)) + return PyArray_SetField(self, descr, + offset, op); + } + } + + PyErr_Format(PyExc_ValueError, + "field named %s not found.", + PyString_AsString(index)); + return -1; + } + + mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index); if (mit == NULL) return -1; if (!mit->view) { |