summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-07-20 20:47:20 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2021-07-26 17:16:58 -0700
commit13c313c107e5a85d3d1ce8eff37af5c4022f8cba (patch)
treeca3bcdf5c204c54fe07d814a8fa9207a17f88c5f /numpy/core/arrayprint.py
parent6e5cdc9d0923558dc66ad878f2e5392d29185754 (diff)
downloadnumpy-13c313c107e5a85d3d1ce8eff37af5c4022f8cba.tar.gz
TST: Add C-side "Scaled float" example
This adds a C-side scaled float (actually double), that is available as: SF = np.core._multiarray_umath._get_sfloat_dtype() It supports different scaling factors: a = np.arange(10.).astype(SF(2.)) b = np.arange(10.).astype(SF(0.5)) and casting from double (used there). This commit makes tiny changes in NumPy to support correct printing.
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index f16bcfd39..2a4bef669 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -420,7 +420,9 @@ def _get_format_function(data, **options):
dtype_ = data.dtype
dtypeobj = dtype_.type
formatdict = _get_formatdict(data, **options)
- if issubclass(dtypeobj, _nt.bool_):
+ if dtypeobj is None:
+ return formatdict["numpystr"]()
+ elif issubclass(dtypeobj, _nt.bool_):
return formatdict['bool']()
elif issubclass(dtypeobj, _nt.integer):
if issubclass(dtypeobj, _nt.timedelta64):
@@ -1408,6 +1410,9 @@ def dtype_short_repr(dtype):
>>> dt = np.int64([1, 2]).dtype
>>> assert eval(dtype_short_repr(dt)) == dt
"""
+ if type(dtype).__repr__ != np.dtype.__repr__:
+ # TODO: Custom repr for user DTypes, logic should likely move.
+ return repr(dtype)
if dtype.names is not None:
# structured dtypes give a list or tuple repr
return str(dtype)