Skip to content

Commit

Permalink
MAINT: dtype.name works for NEP 42 dtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Jan 19, 2023
1 parent 0cfbd3c commit 2a5f735
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion numpy/core/_dtype.py
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/tests/test_custom_dtypes.py
Expand Up @@ -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))
Expand Down

0 comments on commit 2a5f735

Please sign in to comment.