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

Function _array_repr_implementation

numpy/core/arrayprint.py:1487–1531  ·  view source on GitHub ↗

Internal version of array_repr() that allows overriding array2string.

(
        arr, max_line_width=None, precision=None, suppress_small=None,
        array2string=array2string)

Source from the content-addressed store, hash-verified

1485
1486
1487def _array_repr_implementation(
1488 arr, max_line_width=None, precision=None, suppress_small=None,
1489 array2string=array2string):
1490 """Internal version of array_repr() that allows overriding array2string."""
1491 if max_line_width is None:
1492 max_line_width = _format_options['linewidth']
1493
1494 if type(arr) is not ndarray:
1495 class_name = type(arr).__name__
1496 else:
1497 class_name = "array"
1498
1499 skipdtype = dtype_is_implied(arr.dtype) and arr.size > 0
1500
1501 prefix = class_name + "("
1502 suffix = ")" if skipdtype else ","
1503
1504 if (_format_options['legacy'] <= 113 and
1505 arr.shape == () and not arr.dtype.names):
1506 lst = repr(arr.item())
1507 elif arr.size > 0 or arr.shape == (0,):
1508 lst = array2string(arr, max_line_width, precision, suppress_small,
1509 ', ', prefix, suffix=suffix)
1510 else: # show zero-length shape unless it is (0,)
1511 lst = "[], shape=%s" % (repr(arr.shape),)
1512
1513 arr_str = prefix + lst + suffix
1514
1515 if skipdtype:
1516 return arr_str
1517
1518 dtype_str = "dtype={})".format(dtype_short_repr(arr.dtype))
1519
1520 # compute whether we should put dtype on a new line: Do so if adding the
1521 # dtype would extend the last line past max_line_width.
1522 # Note: This line gives the correct result even when rfind returns -1.
1523 last_line_len = len(arr_str) - (arr_str.rfind('\n') + 1)
1524 spacer = " "
1525 if _format_options['legacy'] <= 113:
1526 if issubclass(arr.dtype.type, flexible):
1527 spacer = '\n' + ' '*len(class_name + "(")
1528 elif last_line_len + len(dtype_str) + 1 > max_line_width:
1529 spacer = '\n' + ' '*len(class_name + "(")
1530
1531 return arr_str + spacer + dtype_str
1532
1533
1534def _array_repr_dispatcher(

Callers 1

array_reprFunction · 0.85

Calls 5

dtype_is_impliedFunction · 0.85
array2stringFunction · 0.85
dtype_short_reprFunction · 0.85
itemMethod · 0.80
rfindMethod · 0.80

Tested by

no test coverage detected