From dcc919c7fbfbb5574a1a8b676566d06cbffa070a Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 30 Nov 2017 00:33:12 -0800 Subject: 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. --- numpy/core/arrayprint.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'numpy/core/arrayprint.py') 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) -- cgit v1.2.1