Skip to content

Commit fdd5c2d

Browse files
committed
MAINT: Combine legacy sections of _formatArray
1 parent cd5bc3c commit fdd5c2d

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

numpy/core/arrayprint.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,14 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix,
635635
if rank == 0:
636636
return format_function(a[()]) + '\n'
637637

638-
if summary_insert and 2*edge_items < len(a):
638+
show_summary = summary_insert and 2*edge_items < len(a)
639+
640+
if show_summary:
639641
leading_items = edge_items
640642
trailing_items = edge_items
641-
summary_insert1 = summary_insert + separator
642-
if legacy == '1.13':
643-
summary_insert1 = summary_insert + ', '
644643
else:
645644
leading_items = 0
646645
trailing_items = len(a)
647-
summary_insert1 = ""
648646

649647
if rank == 1:
650648
s = ""
@@ -653,9 +651,12 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix,
653651
word = format_function(a[i]) + separator
654652
s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)
655653

656-
if summary_insert1:
657-
s, line = _extendLine(s, line, summary_insert1, max_line_len,
658-
next_line_prefix)
654+
if show_summary:
655+
if legacy == '1.13':
656+
word = summary_insert + ", "
657+
else:
658+
word = summary_insert + separator
659+
s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)
659660

660661
for i in range(trailing_items, 1, -1):
661662
word = format_function(a[-i]) + separator
@@ -667,29 +668,29 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix,
667668
s = '[' + s[len(next_line_prefix):]
668669
else:
669670
s = '['
670-
sep = separator.rstrip()
671-
line_sep = '\n'*max(rank-1, 1)
671+
line_sep = separator.rstrip() + '\n'*(rank - 1)
672672
for i in range(leading_items):
673673
if i > 0:
674674
s += next_line_prefix
675675
s += _formatArray(a[i], format_function, rank-1, max_line_len,
676676
" " + next_line_prefix, separator, edge_items,
677677
summary_insert, legacy)
678-
s = s.rstrip() + sep.rstrip() + line_sep
678+
s = s.rstrip() + line_sep
679679

680-
if summary_insert1:
680+
if show_summary:
681681
if legacy == '1.13':
682-
s += next_line_prefix + summary_insert1 + "\n"
682+
# trailing space, fixed number of newlines, and fixed separator
683+
s += next_line_prefix + summary_insert + ", \n"
683684
else:
684-
s += next_line_prefix + summary_insert1.strip() + line_sep
685+
s += next_line_prefix + summary_insert + line_sep
685686

686687
for i in range(trailing_items, 1, -1):
687688
if leading_items or i != trailing_items:
688689
s += next_line_prefix
689690
s += _formatArray(a[-i], format_function, rank-1, max_line_len,
690691
" " + next_line_prefix, separator, edge_items,
691692
summary_insert, legacy)
692-
s = s.rstrip() + sep.rstrip() + line_sep
693+
s = s.rstrip() + line_sep
693694
if leading_items or trailing_items > 1:
694695
s += next_line_prefix
695696
s += _formatArray(a[-1], format_function, rank-1, max_line_len,

0 commit comments

Comments
 (0)