summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-01-11 22:24:18 -0800
committerEric Wieser <wieser.eric@gmail.com>2018-02-15 00:53:20 -0800
commitfed44d7c309d0c2fd7c193efa39ba59652a43c44 (patch)
tree4a296cf7695cec4eb3eb3e274633680a3a0114ea /numpy
parent7a3344a461fdb25c55cd5e4fa52abda895f01e20 (diff)
downloadnumpy-fed44d7c309d0c2fd7c193efa39ba59652a43c44.tar.gz
ENH: Always show dtype fields in the array repr, even for non-void
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/arrayprint.py17
-rw-r--r--numpy/core/tests/test_multiarray.py3
2 files changed, 13 insertions, 7 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 3554fe3c4..929f55f5a 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -1254,6 +1254,11 @@ def dtype_is_implied(dtype):
dtype = np.dtype(dtype)
if _format_options['legacy'] == '1.13' and dtype.type == bool_:
return False
+
+ # not just void types can be structured, and names are not part of the repr
+ if dtype.names is not None:
+ return False
+
return dtype.type in _typelessdata
@@ -1266,12 +1271,12 @@ def dtype_short_repr(dtype):
>>> from numpy import *
>>> assert eval(dtype_short_repr(dt)) == dt
"""
- # handle these separately so they don't give garbage like str256
- if issubclass(dtype.type, flexible):
- if dtype.names is not None:
- return "%s" % str(dtype)
- else:
- return "'%s'" % str(dtype)
+ if dtype.names is not None:
+ # structured dtypes give a list or tuple repr
+ return str(dtype)
+ elif issubclass(dtype.type, flexible):
+ # handle these separately so they don't give garbage like str256
+ return "'%s'" % str(dtype)
typename = dtype.name
# quote typenames which can't be represented as python variable names
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index f17fa573e..fe86b629a 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -485,7 +485,8 @@ class TestDtypedescr(object):
# gh-9821
arr_int = np.zeros(4, dt_int)
- assert_equal(repr(arr_int), "array([0, 0, 0, 0])")
+ assert_equal(repr(arr_int),
+ "array([0, 0, 0, 0], dtype=(numpy.int32, [('a', '<i2'), ('b', '<i2')]))")
class TestZeroRank(object):