summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorAllan Haldane <ealloc@gmail.com>2017-12-01 16:20:17 +0100
committerGitHub <noreply@github.com>2017-12-01 16:20:17 +0100
commitcd5bc3c9157ed8d6f6df518ca70fa6037350d279 (patch)
tree3c8b8e9081da58ab3c20f5f523ef6b15578c2bd6 /numpy/core
parent5e5e031cf69380ce105e322d38052bc0689a65b4 (diff)
parent737c3c48d0fd3efaa2f863788aa48ee119c13d3e (diff)
downloadnumpy-cd5bc3c9157ed8d6f6df518ca70fa6037350d279.tar.gz
Merge pull request #10136 from eric-wieser/fix-_leading_trailing-edge_items
BUG: edgeitems kwarg is ignored
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/arrayprint.py11
-rw-r--r--numpy/core/tests/test_arrayprint.py8
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."""