diff options
| author | Eric Wieser <wieser.eric@gmail.com> | 2017-11-30 08:57:49 -0800 |
|---|---|---|
| committer | Eric Wieser <wieser.eric@gmail.com> | 2017-11-30 19:40:04 -0800 |
| commit | 737c3c48d0fd3efaa2f863788aa48ee119c13d3e (patch) | |
| tree | 3c8b8e9081da58ab3c20f5f523ef6b15578c2bd6 /numpy | |
| parent | 5e5e031cf69380ce105e322d38052bc0689a65b4 (diff) | |
| download | numpy-737c3c48d0fd3efaa2f863788aa48ee119c13d3e.tar.gz | |
BUG: edgeitems kwarg is ignored
The global settings were being used instead
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/arrayprint.py | 11 | ||||
| -rw-r--r-- | numpy/core/tests/test_arrayprint.py | 8 |
2 files changed, 13 insertions, 6 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 93a659616..7b2b37694 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -273,25 +273,24 @@ def get_printoptions(): return _format_options.copy() -def _leading_trailing(a, index=()): +def _leading_trailing(a, edgeitems, index=()): """ Keep only the N-D corners (leading and trailing edges) of an array. Should be passed a base-class ndarray, since it makes no guarantees about preserving subclasses. """ - edgeitems = _format_options['edgeitems'] axis = len(index) if axis == a.ndim: return a[index] if a.shape[axis] > 2*edgeitems: return concatenate(( - _leading_trailing(a, index + np.index_exp[ :edgeitems]), - _leading_trailing(a, index + np.index_exp[-edgeitems:]) + _leading_trailing(a, edgeitems, index + np.index_exp[ :edgeitems]), + _leading_trailing(a, edgeitems, index + np.index_exp[-edgeitems:]) ), axis=axis) else: - return _leading_trailing(a, index + np.index_exp[:]) + return _leading_trailing(a, edgeitems, index + np.index_exp[:]) def _object_format(o): @@ -437,7 +436,7 @@ def _array2string(a, options, separator=' ', prefix=""): if a.size > options['threshold']: summary_insert = "..." - data = _leading_trailing(data) + data = _leading_trailing(data, options['edgeitems']) else: summary_insert = "" diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 4d67d6eac..b63957c72 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -230,6 +230,14 @@ class TestArray2String(object): assert_equal(eval(repr(a), vars(np)), a) assert_equal(eval(repr(a[0]), vars(np)), a[0]) + def test_edgeitems_kwarg(self): + # previously the global print options would be taken over the kwarg + arr = np.zeros(3, int) + assert_equal( + np.array2string(arr, edgeitems=1, threshold=0), + "[0 ... 0]" + ) + class TestPrintOptions(object): """Test getting and setting global print options.""" |
