MCPcopy
hub / github.com/numpy/numpy / _get_format_function

Function _get_format_function

numpy/_core/arrayprint.py:526–572  ·  view source on GitHub ↗

find the right formatting function for the dtype_

(data, **options)

Source from the content-addressed store, hash-verified

524 return formatdict
525
526def _get_format_function(data, **options):
527 """
528 find the right formatting function for the dtype_
529 """
530 dtype_ = data.dtype
531 dtypeobj = dtype_.type
532 formatdict = _get_formatdict(data, **options)
533
534 if dtypeobj is None:
535 return formatdict["numpystr"]()
536 elif (getattr(dtypeobj, "__module__", None) != "numpy"
537 and not issubclass(dtypeobj, str)):
538 # Use `str()` as a default format for non-NumPy dtypes. This should be
539 # improved. We use `str` assuming that `repr` is likely to duplicate
540 # information that is contained in the dtype.
541 # (Do this early, because e.g. quaddtype subclasses floating.)
542 return formatdict['void']()
543 elif issubclass(dtypeobj, _nt.bool):
544 return formatdict['bool']()
545 elif issubclass(dtypeobj, _nt.integer):
546 if issubclass(dtypeobj, _nt.timedelta64):
547 return formatdict['timedelta']()
548 else:
549 return formatdict['int']()
550 elif issubclass(dtypeobj, _nt.floating):
551 if issubclass(dtypeobj, _nt.longdouble):
552 return formatdict['longfloat']()
553 else:
554 return formatdict['float']()
555 elif issubclass(dtypeobj, _nt.complexfloating):
556 if issubclass(dtypeobj, _nt.clongdouble):
557 return formatdict['longcomplexfloat']()
558 else:
559 return formatdict['complexfloat']()
560 elif issubclass(dtypeobj, (_nt.str_, _nt.bytes_)):
561 return formatdict['numpystr']()
562 elif issubclass(dtypeobj, _nt.datetime64):
563 return formatdict['datetime']()
564 elif issubclass(dtypeobj, _nt.object_):
565 return formatdict['object']()
566 elif issubclass(dtypeobj, _nt.void):
567 if dtype_.names is not None:
568 return StructuredVoidFormat.from_data(data, **options)
569 else:
570 return formatdict['void']()
571 else:
572 return formatdict['numpystr']()
573
574
575def _recursive_guard(fillvalue='...'):

Callers 2

_array2stringFunction · 0.85
from_dataMethod · 0.85

Calls 2

_get_formatdictFunction · 0.85
from_dataMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…