summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
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,)