MCPcopy Create free account
hub / github.com/numpy/numpy / _newnames

Function _newnames

numpy/core/_internal.py:395–416  ·  view source on GitHub ↗

Given a datatype and an order object, return a new names tuple, with the order indicated

(datatype, order)

Source from the content-addressed store, hash-verified

393
394
395def _newnames(datatype, order):
396 """
397 Given a datatype and an order object, return a new names tuple, with the
398 order indicated
399 """
400 oldnames = datatype.names
401 nameslist = list(oldnames)
402 if isinstance(order, str):
403 order = [order]
404 seen = set()
405 if isinstance(order, (list, tuple)):
406 for name in order:
407 try:
408 nameslist.remove(name)
409 except ValueError:
410 if name in seen:
411 raise ValueError(f"duplicate field name: {name}") from None
412 else:
413 raise ValueError(f"unknown field name: {name}") from None
414 seen.add(name)
415 return tuple(list(order) + nameslist)
416 raise ValueError(f"unsupported order value: {order}")
417
418def _copy_fields(ary):
419 """Return copy of structured array with padding between fields removed.

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected