8000 MAINT: dtype.name works for NEP 42 dtypes · numpy/numpy@61d82aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 61d82aa

Browse files
committed
MAINT: dtype.name works for NEP 42 dtypes
1 parent 0cfbd3c commit 61d82aa

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

numpy/core/_dtype.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def _name_includes_bit_suffix(dtype):
334334
elif dtype.type == np.bool_:
335335
# implied
336336
return False
337+
elif dtype.type is None:
338+
return True
337339
elif np.issubdtype(dtype, np.flexible) and _isunsized(dtype):
338340
# unspecified
339341
return False
@@ -351,6 +353,8 @@ def _name_get(dtype):
351353
if issubclass(dtype.type, np.void):
352354
# historically, void subclasses preserve their name, eg `record64`
353355
name = dtype.type.__name__
356+
elif dtype.kind == '\x00':
357+
name = type(dtype).__name__
354358
else:
355359
name = _kind_name(dtype)
356360

numpy/core/tests/test_custom_dtypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def test_repr(self):
4545
# Check the repr, mainly to cover the code paths:
4646
assert repr(SF(scaling=1.)) == "_ScaledFloatTestDType(scaling=1.0)"
4747

48+
def test_dtype_name(self):
49+
assert SF(1.).name == "_ScaledFloatTestDType64"
50+
4851
@pytest.mark.parametrize("scaling", [1., -1., 2.])
4952
def test_sfloat_from_float(self, scaling):
5053
a = np.array([1., 2., 3.]).astype(dtype=SF(scaling))

0 commit comments

Comments
 (0)
0