diff --git a/numpy/core/_dtype.py b/numpy/core/_dtype.py index 3db80c17eebe..038058c1ad61 100644 --- a/numpy/core/_dtype.py +++ b/numpy/core/_dtype.py @@ -334,6 +334,8 @@ def _name_includes_bit_suffix(dtype): elif dtype.type == np.bool_: # implied return False + elif dtype.type is None: + return True elif np.issubdtype(dtype, np.flexible) and _isunsized(dtype): # unspecified return False @@ -348,7 +350,9 @@ def _name_get(dtype): # user dtypes don't promise to do anything special return dtype.type.__name__ - if issubclass(dtype.type, np.void): + if dtype.kind == '\x00': + name = type(dtype).__name__ + elif issubclass(dtype.type, np.void): # historically, void subclasses preserve their name, eg `record64` name = dtype.type.__name__ else: diff --git a/numpy/core/tests/test_custom_dtypes.py b/numpy/core/tests/test_custom_dtypes.py index 6bcc45d6b398..185404f09655 100644 --- a/numpy/core/tests/test_custom_dtypes.py +++ b/numpy/core/tests/test_custom_dtypes.py @@ -45,6 +45,9 @@ def test_repr(self): # Check the repr, mainly to cover the code paths: assert repr(SF(scaling=1.)) == "_ScaledFloatTestDType(scaling=1.0)" + def test_dtype_name(self): + assert SF(1.).name == "_ScaledFloatTestDType64" + @pytest.mark.parametrize("scaling", [1., -1., 2.]) def test_sfloat_from_float(self, scaling): a = np.array([1., 2., 3.]).astype(dtype=SF(scaling))