MCPcopy Index your code
hub / github.com/numpy/numpy / _get_formatdict

Function _get_formatdict

numpy/_core/arrayprint.py:476–524  ·  view source on GitHub ↗
(data, *, precision, floatmode, suppress, sign, legacy,
                    formatter, **kwargs)

Source from the content-addressed store, hash-verified

474 return str(x)
475
476def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy,
477 formatter, **kwargs):
478 # note: extra arguments in kwargs are ignored
479
480 # wrapped in lambdas to avoid taking a code path
481 # with the wrong type of data
482 formatdict = {
483 'bool': lambda: BoolFormat(data),
484 'int': lambda: IntegerFormat(data, sign),
485 'float': lambda: FloatingFormat(
486 data, precision, floatmode, suppress, sign, legacy=legacy),
487 'longfloat': lambda: FloatingFormat(
488 data, precision, floatmode, suppress, sign, legacy=legacy),
489 'complexfloat': lambda: ComplexFloatingFormat(
490 data, precision, floatmode, suppress, sign, legacy=legacy),
491 'longcomplexfloat': lambda: ComplexFloatingFormat(
492 data, precision, floatmode, suppress, sign, legacy=legacy),
493 'datetime': lambda: DatetimeFormat(data, legacy=legacy),
494 'timedelta': lambda: TimedeltaFormat(data),
495 'object': lambda: _object_format,
496 'void': lambda: str_format,
497 'numpystr': lambda: repr_format}
498
499 # we need to wrap values in `formatter` in a lambda, so that the interface
500 # is the same as the above values.
501 def indirect(x):
502 return lambda: x
503
504 if formatter is not None:
505 fkeys = [k for k in formatter.keys() if formatter[k] is not None]
506 if 'all' in fkeys:
507 for key in formatdict.keys():
508 formatdict[key] = indirect(formatter['all'])
509 if 'int_kind' in fkeys:
510 for key in ['int']:
511 formatdict[key] = indirect(formatter['int_kind'])
512 if 'float_kind' in fkeys:
513 for key in ['float', 'longfloat']:
514 formatdict[key] = indirect(formatter['float_kind'])
515 if 'complex_kind' in fkeys:
516 for key in ['complexfloat', 'longcomplexfloat']:
517 formatdict[key] = indirect(formatter['complex_kind'])
518 if 'str_kind' in fkeys:
519 formatdict['numpystr'] = indirect(formatter['str_kind'])
520 for key in formatdict.keys():
521 if key in fkeys:
522 formatdict[key] = indirect(formatter[key])
523
524 return formatdict
525
526def _get_format_function(data, **options):
527 """

Callers 1

_get_format_functionFunction · 0.85

Calls 8

BoolFormatClass · 0.85
IntegerFormatClass · 0.85
FloatingFormatClass · 0.85
DatetimeFormatClass · 0.85
TimedeltaFormatClass · 0.85
indirectFunction · 0.85
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…