Skip to content

Commit

Permalink
ENH: Always show dtype fields in the array repr, even for non-void
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Feb 15, 2018
1 parent 7a3344a commit fed44d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions numpy/core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ def test_structured_non_void(self):

# 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):
Expand Down

0 comments on commit fed44d7

Please sign in to comment.