diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-12-07 19:41:09 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-12-07 20:58:02 -0800 |
commit | e7f84cdf526f872d797eba5786bd16e580212f4f (patch) | |
tree | 8eef11f7fdcd6dcbde821a73b036cde115f7350f /numpy/core/arrayprint.py | |
parent | d542d141f0667abd3501b48b38de245d5bbba4e1 (diff) | |
download | numpy-e7f84cdf526f872d797eba5786bd16e580212f4f.tar.gz |
BUG: Output of formatArray is not always wrapped correctly
The old behaviour is kept under the legacy='1.13' flag, as usual
See tests for the changes.
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index db6a60b0d..fb8d99895 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -615,15 +615,15 @@ def array2string(a, max_line_width=None, precision=None, return _array2string(a, options, separator, prefix) -def _extendLine(s, line, word, max_line_len, next_line_prefix): - if len((line + word).rstrip()) > max_line_len: +def _extendLine(s, line, word, line_width, next_line_prefix): + if len(line) + len(word) > line_width: s += line.rstrip() + "\n" line = next_line_prefix line += word return s, line -def _formatArray(a, format_function, max_line_len, next_line_prefix, +def _formatArray(a, format_function, line_width, next_line_prefix, separator, edge_items, summary_insert, legacy): """formatArray is designed for two modes of operation: @@ -661,24 +661,36 @@ def _formatArray(a, format_function, max_line_len, next_line_prefix, # last axis (rows) - wrap elements if they would not fit on one line if axes_left == 1: + # the length up until the beginning of the separator / bracket + if legacy == '1.13': + elem_width = line_width - len(separator.rstrip()) + else: + elem_width = line_width - max(len(separator.rstrip()), len(']')) + line = hanging_indent for i in range(leading_items): - word = recurser(index + (i,), next_hanging_indent) + separator - s, line = _extendLine(s, line, word, max_line_len, hanging_indent) + word = recurser(index + (i,), next_hanging_indent) + s, line = _extendLine(s, line, word, elem_width, hanging_indent) + line += separator if show_summary: + s, line = _extendLine(s, line, summary_insert, elem_width, hanging_indent) if legacy == '1.13': - word = summary_insert + ", " + line += ", " else: - word = summary_insert + separator - s, line = _extendLine(s, line, word, max_line_len, hanging_indent) + line += separator for i in range(trailing_items, 1, -1): - word = recurser(index + (-i,), next_hanging_indent) + separator - s, line = _extendLine(s, line, word, max_line_len, hanging_indent) + word = recurser(index + (-i,), next_hanging_indent) + s, line = _extendLine(s, line, word, elem_width, hanging_indent) + line += separator + if legacy == '1.13': + # width of the seperator is not considered on 1.13 + elem_width = line_width word = recurser(index + (-1,), next_hanging_indent) - s, line = _extendLine(s, line, word, max_line_len, hanging_indent) + s, line = _extendLine(s, line, word, elem_width, hanging_indent) + s += line # other axes - insert newlines between rows |