diff options
author | Allan Haldane <ealloc@gmail.com> | 2017-11-18 19:39:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-18 19:39:29 +0100 |
commit | 365fc9d19b52325bd5618aac1a3fa7b8a6be3b3c (patch) | |
tree | fba9b1e900840c057cea1f7bdc872c477e0aa60c /numpy/core/arrayprint.py | |
parent | 2d140f11857fc1353d6b2dcbb801e693128fd09a (diff) | |
parent | ac6b1a902b99e340cf7eeeeb7392c91e38db9dd8 (diff) | |
download | numpy-365fc9d19b52325bd5618aac1a3fa7b8a6be3b3c.tar.gz |
Merge pull request #10021 from eric-wieser/no-dtype-bool-repr
ENH: Don't show the boolean dtype in array_repr
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 9174328bf..9f5039c57 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -1137,12 +1137,44 @@ def _void_scalar_repr(x): return StructureFormat.from_data(array(x), **_format_options)(x) -_typelessdata = [int_, float_, complex_] +_typelessdata = [int_, float_, complex_, bool_] if issubclass(intc, int): _typelessdata.append(intc) if issubclass(longlong, int): _typelessdata.append(longlong) + +def dtype_is_implied(dtype): + """ + Determine if the given dtype is implied by the representation of its values. + + Parameters + ---------- + dtype : dtype + Data type + + Returns + ------- + implied : bool + True if the dtype is implied by the representation of its values. + + Examples + -------- + >>> np.core.arrayprint.dtype_is_implied(int) + True + >>> np.array([1, 2, 3], int) + array([1, 2, 3]) + >>> np.core.arrayprint.dtype_is_implied(np.int8) + False + >>> np.array([1, 2, 3], np.int8) + array([1, 2, 3], dtype=np.int8) + """ + dtype = np.dtype(dtype) + if _format_options['legacy'] and dtype.type == bool_: + return False + return dtype.type in _typelessdata + + def array_repr(arr, max_line_width=None, precision=None, suppress_small=None): """ Return the string representation of an array. @@ -1199,7 +1231,7 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None): else: # show zero-length shape unless it is (0,) lst = "[], shape=%s" % (repr(arr.shape),) - skipdtype = (arr.dtype.type in _typelessdata) and arr.size > 0 + skipdtype = dtype_is_implied(arr.dtype) and arr.size > 0 if skipdtype: return "%s(%s)" % (class_name, lst) |