From 04d2f0494f0fef2ede1461053b6cfc9bd37aaf2f Mon Sep 17 00:00:00 2001 From: Allan Haldane Date: Sun, 25 Feb 2018 14:52:41 -0500 Subject: BUG: Further back-compat fix for subclassed array repr Fixes #10663 --- numpy/core/arrayprint.py | 7 ++--- numpy/core/tests/test_arrayprint.py | 53 ++++++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index cbe95f51b..7dc73d6de 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -471,14 +471,15 @@ def _array2string(a, options, separator=' ', prefix=""): # The formatter __init__s in _get_format_function cannot deal with # subclasses yet, and we also need to avoid recursion issues in # _formatArray with subclasses which return 0d arrays in place of scalars - a = asarray(a) + data = asarray(a) + if a.shape == (): + a = data if a.size > options['threshold']: summary_insert = "..." - data = _leading_trailing(a, options['edgeitems']) + data = _leading_trailing(data, options['edgeitems']) else: summary_insert = "" - data = a # find the right formatting function for the array format_function = _get_format_function(data, **options) diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 88aaa3403..309df8545 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -5,7 +5,7 @@ import sys, gc import numpy as np from numpy.testing import ( - run_module_suite, assert_, assert_equal, assert_raises, assert_warns + run_module_suite, assert_, assert_equal, assert_raises, assert_warns, dec ) import textwrap @@ -34,6 +34,27 @@ class TestArrayRepr(object): " [(1,), (1,)]], dtype=[('a', '