From 13c313c107e5a85d3d1ce8eff37af5c4022f8cba Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Tue, 20 Jul 2021 20:47:20 -0500 Subject: 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. --- numpy/core/arrayprint.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'numpy/core/arrayprint.py') 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) -- cgit v1.2.1