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

Function _extendLine_pretty

numpy/core/arrayprint.py:753–778  ·  view source on GitHub ↗

Extends line with nicely formatted (possibly multi-line) string ``word``.

(s, line, word, line_width, next_line_prefix, legacy)

Source from the content-addressed store, hash-verified

751
752
753def _extendLine_pretty(s, line, word, line_width, next_line_prefix, legacy):
754 """
755 Extends line with nicely formatted (possibly multi-line) string ``word``.
756 """
757 words = word.splitlines()
758 if len(words) == 1 or legacy <= 113:
759 return _extendLine(s, line, word, line_width, next_line_prefix, legacy)
760
761 max_word_length = max(len(word) for word in words)
762 if (len(line) + max_word_length > line_width and
763 len(line) > len(next_line_prefix)):
764 s += line.rstrip() + '\n'
765 line = next_line_prefix + words[0]
766 indent = next_line_prefix
767 else:
768 indent = len(line)*' '
769 line += words[0]
770
771 for word in words[1::]:
772 s += line.rstrip() + '\n'
773 line = indent + word
774
775 suffix_length = max_word_length - len(words[-1])
776 line += suffix_length*' '
777
778 return s, line
779
780def _formatArray(a, format_function, line_width, next_line_prefix,
781 separator, edge_items, summary_insert, legacy):

Callers 1

recurserFunction · 0.85

Calls 4

_extendLineFunction · 0.85
splitlinesMethod · 0.80
rstripMethod · 0.80
maxFunction · 0.70

Tested by

no test coverage detected