diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-22 00:19:16 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-25 16:00:25 +0000 |
commit | 3461ea868bc7520d4569f7d61397044cf4e593d0 (patch) | |
tree | d90dca9110e50093459f041ed9e17050498ea843 /numpy/core/numeric.py | |
parent | eb271d95c0c9f3821009330d858a261b4b861bfe (diff) | |
download | numpy-3461ea868bc7520d4569f7d61397044cf4e593d0.tar.gz |
ENH: Fix alignment of repr for array subclasses
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 896ad7f6a..01dd46c3c 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1890,35 +1890,35 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None): 'array([ 0.000001, 0. , 2. , 3. ])' """ + if type(arr) is not ndarray: + class_name = type(arr).__name__ + else: + class_name = "array" + if arr.size > 0 or arr.shape == (0,): lst = array2string(arr, max_line_width, precision, suppress_small, - ', ', "array(") + ', ', class_name + "(") else: # show zero-length shape unless it is (0,) lst = "[], shape=%s" % (repr(arr.shape),) - if arr.__class__ is not ndarray: - cName = arr.__class__.__name__ - else: - cName = "array" - skipdtype = (arr.dtype.type in _typelessdata) and arr.size > 0 if skipdtype: - return "%s(%s)" % (cName, lst) + return "%s(%s)" % (class_name, lst) else: typename = arr.dtype.name # Quote typename in the output if it is "complex". if typename and not (typename[0].isalpha() and typename.isalnum()): typename = "'%s'" % typename - lf = '' + lf = ' ' if issubclass(arr.dtype.type, flexible): if arr.dtype.names: typename = "%s" % str(arr.dtype) else: typename = "'%s'" % str(arr.dtype) - lf = '\n'+' '*len("array(") - return cName + "(%s, %sdtype=%s)" % (lst, lf, typename) + lf = '\n'+' '*len(class_name + "(") + return "%s(%s,%sdtype=%s)" % (class_name, lst, lf, typename) def array_str(a, max_line_width=None, precision=None, suppress_small=None): |