diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-12-09 17:15:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-09 17:15:55 -0700 |
commit | 7b0252c1a49ad8627bb58eb8095541e19aea5239 (patch) | |
tree | 1824ed83f906b51359a25f4eb8131b4363e0d0e0 /numpy/core/arrayprint.py | |
parent | 5c16f535e7515c2394b19cc6778ad9b5ae24d729 (diff) | |
parent | c9052f05ac3a273141f1d222745a420b6b49ed6c (diff) | |
download | numpy-7b0252c1a49ad8627bb58eb8095541e19aea5239.tar.gz |
Merge pull request #10187 from eric-wieser/fix-extra-space
BUG: Extra space is inserted on first line for long elements
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index eaec91259..238e1782f 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -622,8 +622,14 @@ def array2string(a, max_line_width=None, precision=None, return _array2string(a, options, separator, prefix) -def _extendLine(s, line, word, line_width, next_line_prefix): - if len(line) + len(word) > line_width: +def _extendLine(s, line, word, line_width, next_line_prefix, legacy): + needs_wrap = len(line) + len(word) > line_width + if legacy != '1.13': + s# don't wrap lines if it won't help + if len(line) <= len(next_line_prefix): + needs_wrap = False + + if needs_wrap: s += line.rstrip() + "\n" line = next_line_prefix line += word @@ -682,11 +688,13 @@ def _formatArray(a, format_function, line_width, next_line_prefix, line = hanging_indent for i in range(leading_items): word = recurser(index + (i,), next_hanging_indent, next_width) - s, line = _extendLine(s, line, word, elem_width, hanging_indent) + s, line = _extendLine( + s, line, word, elem_width, hanging_indent, legacy) line += separator if show_summary: - s, line = _extendLine(s, line, summary_insert, elem_width, hanging_indent) + s, line = _extendLine( + s, line, summary_insert, elem_width, hanging_indent, legacy) if legacy == '1.13': line += ", " else: @@ -694,14 +702,16 @@ def _formatArray(a, format_function, line_width, next_line_prefix, for i in range(trailing_items, 1, -1): word = recurser(index + (-i,), next_hanging_indent, next_width) - s, line = _extendLine(s, line, word, elem_width, hanging_indent) + s, line = _extendLine( + s, line, word, elem_width, hanging_indent, legacy) line += separator if legacy == '1.13': # width of the seperator is not considered on 1.13 elem_width = curr_width word = recurser(index + (-1,), next_hanging_indent, next_width) - s, line = _extendLine(s, line, word, elem_width, hanging_indent) + s, line = _extendLine( + s, line, word, elem_width, hanging_indent, legacy) s += line |