8000 Merge pull request #7660 from ahaldane/fix_7493_1.11 · numpy/numpy@693bead · GitHub
[go: up one dir, main page]

Skip to content

Commit 693bead

Browse files
committed
Merge pull request #7660 from ahaldane/fix_7493_1.11
Backport 7659, BUG: Temporary fix for str(mvoid) for object field types
2 parents a62cf4e + a48f422 commit 693bead

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

numpy/ma/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5954,7 +5954,14 @@ def __str__(self):
59545954
return self._data.__str__()
59555955
printopt = masked_print_option
59565956
rdtype = _recursive_make_descr(self._data.dtype, "O")
5957-
res = np.array([self._data]).astype(rdtype)
5957+
5958+
# temporary hack to fix gh-7493. A more permanent fix
5959+
# is proposed in gh-6053, after which the next two
5960+
# lines should be changed to
5961+
# res = np.array([self._data], dtype=rdtype)
5962+
res = np.empty(1, rdtype)
5963+
res[:1] = self._data
5964+
59585965
_recursive_printoption(res, self._mask, printopt)
59595966
return str(res[0])
59605967

numpy/ma/tests/test_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@ def test_mvoid_print(self):
757757
finally:
758758
masked_print_option.set_display(ini_display)
759759

760+
# also check if there are object datatypes (see gh-7493)
761+
mx = array([(1,), (2,)], dtype=[('a', 'O')])
762+
assert_equal(str(mx[0]), "(1,)")
763+
760764
def test_mvoid_multidim_print(self):
761765

762766
# regression test for gh-6019

0 commit comments

Comments
 (0)
0