8000 BUG: Fix crash in repr of void subclasses by eric-wieser · Pull Request #12240 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix crash in repr of void subclasses #12240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: Fix crash in repr of void subclasses
Fixes #12206, which was a regression introduced by #10602

Frankly I'd consider the results expected by `test_void_subclass_unsized` and `test_void_subclass_sized` undesirable, but they match the behavior in 1.12.x
  • Loading branch information
eric-wieser committed Oct 22, 2018
commit 0ec2a4f581c32979862468b727cc96df4910d5ed
4 changes: 3 additions & 1 deletion numpy/core/_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def _scalar_str(dtype, short):
else:
return "'%sU%d'" % (byteorder, dtype.itemsize / 4)

elif dtype.type == np.void:
# unlike the other types, subclasses of void are preserved - but
# historically the repr does not actually reveal the subclass
elif issubclass(dtype.type, np.void):
if _isunsized(dtype):
return "'V'"
else:
Expand Down
19 changes: 19 additions & 0 deletions numpy/core/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,25 @@ def test_empty_string_to_object(self):
# Pull request #4722
np.array(["", ""]).astype(object)

def test_void_subclass_unsized(self):
dt = np.dtype(np.record)
assert_equal(repr(dt), "dtype('V')")
assert_equal(str(dt), '|V0')
assert_equal(dt.name, 'record')

def test_void_subclass_sized(self):
dt = np.dtype((np.record, 2))
assert_equal(repr(dt), "dtype('V2')")
assert_equal(str(dt), '|V2')
assert_equal(dt.name, 'record16')

def test_void_subclass_fields(self):
dt = np.dtype((np.record, [('a', '<u2')]))
assert_equal(repr(dt), "dtype((numpy.record, [('a', '<u2')]))")
assert_equal(str(dt), "(numpy.record, [('a', '<u2')])")
assert_equal(dt.name, 'record16')


class TestDtypeAttributeDeletion(object):

def test_dtype_non_writable_attributes_deletion(self):
Expand Down
0