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

Function _get_formatdict

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

Source from the content-addressed store, hash-verified

401 return str(x)
402
403def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy,
404 formatter, **kwargs):
405 # note: extra arguments in kwargs are ignored
406
407 # wrapped in lambdas to avoid taking a code path with the wrong type of data
408 formatdict = {
409 'bool': lambda: BoolFormat(data),
410 'int': lambda: IntegerFormat(data),
411 'float': lambda: FloatingFormat(
412 data, precision, floatmode, suppress, sign, legacy=legacy),
413 'longfloat': lambda: FloatingFormat(
414 data, precision, floatmode, suppress, sign, legacy=legacy),
415 'complexfloat': lambda: ComplexFloatingFormat(
416 data, precision, floatmode, suppress, sign, legacy=legacy),
417 'longcomplexfloat': lambda: ComplexFloatingFormat(
418 data, precision, floatmode, suppress, sign, legacy=legacy),
419 'datetime': lambda: DatetimeFormat(data, legacy=legacy),
420 'timedelta': lambda: TimedeltaFormat(data),
421 'object': lambda: _object_format,
422 'void': lambda: str_format,
423 'numpystr': lambda: repr_format}
424
425 # we need to wrap values in `formatter` in a lambda, so that the interface
426 # is the same as the above values.
427 def indirect(x):
428 return lambda: x
429
430 if formatter is not None:
431 fkeys = [k for k in formatter.keys() if formatter[k] is not None]
432 if 'all' in fkeys:
433 for key in formatdict.keys():
434 formatdict[key] = indirect(formatter['all'])
435 if 'int_kind' in fkeys:
436 for key in ['int']:
437 formatdict[key] = indirect(formatter['int_kind'])
438 if 'float_kind' in fkeys:
439 for key in ['float', 'longfloat']:
440 formatdict[key] = indirect(formatter['float_kind'])
441 if 'complex_kind' in fkeys:
442 for key in ['complexfloat', 'longcomplexfloat']:
443 formatdict[key] = indirect(formatter['complex_kind'])
444 if 'str_kind' in fkeys:
445 formatdict['numpystr'] = indirect(formatter['str_kind'])
446 for key in formatdict.keys():
447 if key in fkeys:
448 formatdict[key] = indirect(formatter[key])
449
450 return formatdict
451
452def _get_format_function(data, **options):
453 """

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.80

Tested by

no test coverage detected