diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-11-30 00:33:12 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-11-30 00:33:12 -0800 |
commit | dcc919c7fbfbb5574a1a8b676566d06cbffa070a (patch) | |
tree | 7d4102979164fbfe99a9dcb3818aac45cf006948 /numpy/core/arrayprint.py | |
parent | 88f8310d8c3049881f78883b70766867e9147177 (diff) | |
download | numpy-dcc919c7fbfbb5574a1a8b676566d06cbffa070a.tar.gz |
BUG: Fix downcasting in _array2string
If there are no elements to remove, _leading_trailing returns a subclass view, rather than its normal behaviour of returning an ndarray copy.
Since we call `asarray` in the other branch of this `if` anyway, we may as well do it in both.
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index e4be810b9..e4a048a42 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -427,12 +427,14 @@ def _recursive_guard(fillvalue='...'): # gracefully handle recursive calls, when object arrays contain themselves @_recursive_guard() def _array2string(a, options, separator=' ', prefix=""): + # The formatter __init__s cannot deal with subclasses yet + data = asarray(a) + if a.size > options['threshold']: summary_insert = "..." - data = _leading_trailing(a) + data = _leading_trailing(data) else: summary_insert = "" - data = asarray(a) # find the right formatting function for the array format_function = _get_format_function(data, **options) |