diff options
| author | Allan Haldane <allan.haldane@gmail.com> | 2017-11-28 18:33:19 -0500 |
|---|---|---|
| committer | Allan Haldane <allan.haldane@gmail.com> | 2017-11-29 00:04:12 -0500 |
| commit | b49b20ff5c5154114eb41254cf449e195b5ba45e (patch) | |
| tree | 3f48edead1f1058c9c5b45d5f55d38d2ca0cfa24 /numpy | |
| parent | fb94b2b33eb04f66b708df6166d861989bc036a9 (diff) | |
| download | numpy-b49b20ff5c5154114eb41254cf449e195b5ba45e.tar.gz | |
BUG: stray comma should be preserved for legacy printing
Fixes #10059
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/arrayprint.py | 19 | ||||
| -rw-r--r-- | numpy/core/tests/test_arrayprint.py | 7 | ||||
| -rw-r--r-- | numpy/ma/tests/test_core.py | 4 |
3 files changed, 20 insertions, 10 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 2aa35224c..e4be810b9 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -443,8 +443,8 @@ def _array2string(a, options, separator=' ', prefix=""): next_line_prefix += " "*len(prefix) lst = _formatArray(a, format_function, a.ndim, options['linewidth'], - next_line_prefix, separator, - options['edgeitems'], summary_insert)[:-1] + next_line_prefix, separator, options['edgeitems'], + summary_insert, options['legacy'])[:-1] return lst @@ -617,8 +617,8 @@ def _extendLine(s, line, word, max_line_len, next_line_prefix): return s, line -def _formatArray(a, format_function, rank, max_line_len, - next_line_prefix, separator, edge_items, summary_insert): +def _formatArray(a, format_function, rank, max_line_len, next_line_prefix, + separator, edge_items, summary_insert, legacy): """formatArray is designed for two modes of operation: 1. Full output @@ -633,6 +633,8 @@ def _formatArray(a, format_function, rank, max_line_len, leading_items = edge_items trailing_items = edge_items summary_insert1 = summary_insert + separator + if legacy == '1.13': + summary_insert1 = summary_insert + ', ' else: leading_items = 0 trailing_items = len(a) @@ -646,7 +648,8 @@ def _formatArray(a, format_function, rank, max_line_len, s, line = _extendLine(s, line, word, max_line_len, next_line_prefix) if summary_insert1: - s, line = _extendLine(s, line, summary_insert1, max_line_len, next_line_prefix) + s, line = _extendLine(s, line, summary_insert1, max_line_len, + next_line_prefix) for i in range(trailing_items, 1, -1): word = format_function(a[-i]) + separator @@ -664,7 +667,7 @@ def _formatArray(a, format_function, rank, max_line_len, s += next_line_prefix s += _formatArray(a[i], format_function, rank-1, max_line_len, " " + next_line_prefix, separator, edge_items, - summary_insert) + summary_insert, legacy) s = s.rstrip() + sep.rstrip() + '\n'*max(rank-1, 1) if summary_insert1: @@ -675,13 +678,13 @@ def _formatArray(a, format_function, rank, max_line_len, s += next_line_prefix s += _formatArray(a[-i], format_function, rank-1, max_line_len, " " + next_line_prefix, separator, edge_items, - summary_insert) + summary_insert, legacy) s = s.rstrip() + sep.rstrip() + '\n'*max(rank-1, 1) if leading_items or trailing_items > 1: s += next_line_prefix s += _formatArray(a[-1], format_function, rank-1, max_line_len, " " + next_line_prefix, separator, edge_items, - summary_insert).rstrip()+']\n' + summary_insert, legacy).rstrip()+']\n' return s diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 9719e8668..49161ad5e 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -487,6 +487,13 @@ class TestPrintOptions(object): '1.1234567891234568') assert_equal(str(np.complex128(complex(1, np.nan))), '(1+nanj)') + def test_legacy_stray_comma(self): + np.set_printoptions(legacy='1.13') + assert_equal(str(np.arange(10000)), '[ 0 1 2 ..., 9997 9998 9999]') + + np.set_printoptions(legacy=False) + assert_equal(str(np.arange(10000)), '[ 0 1 2 ... 9997 9998 9999]') + def test_dtype_linewidth_wrapping(self): np.set_printoptions(linewidth=75) assert_equal(repr(np.arange(10,20., dtype='f4')), diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index be56833fd..cc447e37e 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -571,8 +571,8 @@ class TestMaskedArray(object): a[1:50] = np.ma.masked assert_equal( repr(a), - 'masked_array(data = [0 -- -- ... 1997 1998 1999],\n' - ' mask = [False True True ... False False False],\n' + 'masked_array(data = [0 -- -- ..., 1997 1998 1999],\n' + ' mask = [False True True ..., False False False],\n' ' fill_value = 999999)\n' ) finally: |
