diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 447d58884090..18e902bffb4c 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -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]) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index c7b8bb3a8d2e..95afe4ce9972 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -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