From 6df0b6e2b79aad40715f933b561660f951693289 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 28 Nov 2017 23:29:04 -0800 Subject: ENH: Strip trailing spaces and add newlines in truncated arrayprint This is otherwise pretty strict about trailing spaces, so we may as well cut them here too, especially since the repr has changed here already. The newlines look better to me for multi-dimensional arrays too. --- numpy/core/arrayprint.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'numpy/core/arrayprint.py') diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index e4be810b9..156a057a3 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -662,16 +662,20 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix, else: s = '[' sep = separator.rstrip() + line_sep = '\n'*max(rank-1, 1) for i in range(leading_items): if i > 0: s += next_line_prefix s += _formatArray(a[i], format_function, rank-1, max_line_len, " " + next_line_prefix, separator, edge_items, summary_insert, legacy) - s = s.rstrip() + sep.rstrip() + '\n'*max(rank-1, 1) + s = s.rstrip() + sep.rstrip() + line_sep if summary_insert1: - s += next_line_prefix + summary_insert1 + "\n" + if legacy == '1.13': + s += next_line_prefix + summary_insert1 + "\n" + else: + s += next_line_prefix + summary_insert1.strip() + line_sep for i in range(trailing_items, 1, -1): if leading_items or i != trailing_items: @@ -679,7 +683,7 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix, s += _formatArray(a[-i], format_function, rank-1, max_line_len, " " + next_line_prefix, separator, edge_items, summary_insert, legacy) - s = s.rstrip() + sep.rstrip() + '\n'*max(rank-1, 1) + s = s.rstrip() + sep.rstrip() + line_sep if leading_items or trailing_items > 1: s += next_line_prefix s += _formatArray(a[-1], format_function, rank-1, max_line_len, -- cgit v1.2.1