summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-11-04 01:47:36 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-11-04 01:47:36 +0000
commit2b5e6e4c7e74adbd826b28eec4432eadc86ffd92 (patch)
treedc24788217f387f5e2fb8ad83a69de8ca366edbb /numpy/core/_internal.py
parented184cde3c12fc43049951a60434df296e5725f3 (diff)
downloadnumpy-2b5e6e4c7e74adbd826b28eec4432eadc86ffd92.tar.gz
Allow order keyword to sort for sorting record arrays.
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r--numpy/core/_internal.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index fa46a918b..3684ba492 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -267,3 +267,21 @@ class _ctypes(object):
shape = property(get_shape, None, doc="c-types shape")
strides = property(get_strides, None, doc="c-types strides")
_as_parameter_ = property(get_as_parameter, None, doc="_as parameter_")
+
+
+# Given a datatype and an order object
+# return a new names tuple
+# with the order indicated
+def _newnames(datatype, order):
+ oldnames = datatype.names
+ nameslist = list(oldnames)
+ if isinstance(order, str):
+ order = [order]
+ if isinstance(order, (list, tuple)):
+ for name in order:
+ try:
+ nameslist.remove(name)
+ except ValueError:
+ raise ValueError, "unknown field name: %s" % (name,)
+ return tuple(list(order) + nameslist)
+ raise ValueError, "unsupported order value: %s" % (order,)