diff options
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index da173625e..8435574bf 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -1135,6 +1135,36 @@ if issubclass(intc, int): 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) + 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. @@ -1190,7 +1220,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) |