diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-11-04 01:47:36 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-11-04 01:47:36 +0000 |
commit | 2b5e6e4c7e74adbd826b28eec4432eadc86ffd92 (patch) | |
tree | dc24788217f387f5e2fb8ad83a69de8ca366edbb /numpy/core/src/arraymethods.c | |
parent | ed184cde3c12fc43049951a60434df296e5725f3 (diff) | |
download | numpy-2b5e6e4c7e74adbd826b28eec4432eadc86ffd92.tar.gz |
Allow order keyword to sort for sorting record arrays.
Diffstat (limited to 'numpy/core/src/arraymethods.c')
-rw-r--r-- | numpy/core/src/arraymethods.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index 488ed3bf7..b48c0c02b 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -852,14 +852,38 @@ array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) int axis=-1; int val; PyArray_SORTKIND which=PyArray_QUICKSORT; - static char *kwlist[] = {"axis", "kind", NULL}; + PyObject *order=NULL; + PyArray_Descr *saved=NULL; + PyArray_Descr *newd; + static char *kwlist[] = {"axis", "kind", "order", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&O", kwlist, &axis, + PyArray_SortkindConverter, &which, + &order)) + return NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis, - PyArray_SortkindConverter, &which)) - return NULL; + if (order != NULL) { + PyObject *new_name; + saved = self->descr; + if (saved->names == NULL) { + PyErr_SetString(PyExc_ValueError, "Cannot specify " \ + "order with no fields."); + return NULL; + } + new_name = PyObject_CallMethod(_numpy_internal, "_newnames", + "OO", saved, order); + if (new_name == NULL) return NULL; + newd = PyArray_DescrNew(saved); + newd->names = new_name; + self->descr = newd; + } - val = PyArray_Sort(self, axis, which); - if (val < 0) return NULL; + val = PyArray_Sort(self, axis, which); + if (order != NULL) { + Py_XDECREF(self->descr); + self->descr = saved; + } + if (val < 0) return NULL; Py_INCREF(Py_None); return Py_None; } |