diff options
author | molsonkiko <46202915+molsonkiko@users.noreply.github.com> | 2023-03-14 05:57:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 13:57:27 +0100 |
commit | 071388f957c13c1a4f03bc811e3d128335ac686e (patch) | |
tree | e74039b2b95dc6caa5a64db12b3f2982dc34c658 /numpy/core/arrayprint.py | |
parent | 80f7cba7a4bf0970095d7f750abf15bf4b5e364b (diff) | |
download | numpy-071388f957c13c1a4f03bc811e3d128335ac686e.tar.gz |
ENH: show dtype in array repr when endianness is non-native (#23295)
Fx problem where, for example,
np.array([1], dtype='>u2') and np.array([1], dtype='<u2')
both got represented as np.array([1], dtype=uint16), or the dtype is not shown for the default ones (float64, default int).
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index a243366b7..dcfb6e6a8 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -1428,6 +1428,10 @@ def dtype_is_implied(dtype): # not just void types can be structured, and names are not part of the repr if dtype.names is not None: return False + + # should care about endianness *unless size is 1* (e.g., int8, bool) + if not dtype.isnative: + return False return dtype.type in _typelessdata @@ -1453,10 +1457,14 @@ def dtype_short_repr(dtype): return "'%s'" % str(dtype) typename = dtype.name + if not dtype.isnative: + # deal with cases like dtype('<u2') that are identical to an + # established dtype (in this case uint16) + # except that they have a different endianness. + return "'%s'" % str(dtype) # quote typenames which can't be represented as python variable names if typename and not (typename[0].isalpha() and typename.isalnum()): typename = repr(typename) - return typename |