Skip to content

Backport 7659, BUG: Temporary fix for str(mvoid) for object field types #7660

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
May 23, 2016
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
9 changes: 8 additions & 1 deletion numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5954,7 +5954,14 @@ def __str__(self):
return self._data.__str__()
printopt = masked_print_option
rdtype = _recursive_make_descr(self._data.dtype, "O")
res = np.array([self._data]).astype(rdtype)

# temporary hack to fix gh-7493. A more permanent fix
# is proposed in gh-6053, after which the next two
# lines should be changed to
# res = np.array([self._data], dtype=rdtype)
res = np.empty(1, rdtype)
res[:1] = self._data

_recursive_printoption(res, self._mask, printopt)
return str(res[0])

Expand Down
4 changes: 4 additions & 0 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ def test_mvoid_print(self):
finally:
masked_print_option.set_display(ini_display)

# also check if there are object datatypes (see gh-7493)
mx = array([(1,), (2,)], dtype=[('a', 'O')])
assert_equal(str(mx[0]), "(1,)")

def test_mvoid_multidim_print(self):

# regression test for gh-6019
Expand Down