diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/records.py | 10 | ||||
| -rw-r--r-- | numpy/core/tests/test_records.py | 11 | ||||
| -rw-r--r-- | numpy/ma/core.py | 6 |
3 files changed, 22 insertions, 5 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index b6ff8bf65..76783bb67 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -42,6 +42,7 @@ import os from . import numeric as sb from . import numerictypes as nt from numpy.compat import isfileobj, bytes, long +from .arrayprint import get_printoptions # All of the functions allow formats to be a dtype __all__ = ['record', 'recarray', 'format_parser'] @@ -525,22 +526,25 @@ class recarray(ndarray): if repr_dtype.type is record: repr_dtype = sb.dtype((nt.void, repr_dtype)) prefix = "rec.array(" - fmt = 'rec.array(%s, %sdtype=%s)' + fmt = 'rec.array(%s,%sdtype=%s)' else: # otherwise represent it using np.array plus a view # This should only happen if the user is playing # strange games with dtypes. prefix = "array(" - fmt = 'array(%s, %sdtype=%s).view(numpy.recarray)' + fmt = 'array(%s,%sdtype=%s).view(numpy.recarray)' # get data/shape string. logic taken from numeric.array_repr if self.size > 0 or self.shape == (0,): - lst = sb.array2string(self, separator=', ', prefix=prefix) + lst = sb.array2string( + self, separator=', ', prefix=prefix, suffix=',') else: # show zero-length shape unless it is (0,) lst = "[], shape=%s" % (repr(self.shape),) lf = '\n'+' '*len(prefix) + if get_printoptions()['legacy'] == '1.13': + lf = ' ' + lf # trailing space return fmt % (lst, lf, repr_dtype) def field(self, attr, val=None): diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index 27d35fa65..73cfe3570 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -101,6 +101,17 @@ class TestFromrecords(object): assert_((mine.data1[i] == 0.0)) assert_((mine.data2[i] == 0.0)) + def test_recarray_repr(self): + a = np.array([(1, 0.1), (2, 0.2)], + dtype=[('foo', int), ('bar', float)]) + a = np.rec.array(a) + assert_equal( + repr(a), + textwrap.dedent("""\ + rec.array([(1, 0.1), (2, 0.2)], + dtype=[('foo', '<i4'), ('bar', '<f8')])""") + ) + def test_recarray_from_repr(self): a = np.array([(1,'ABC'), (2, "DEF")], dtype=[('foo', int), ('bar', 'S4')]) diff --git a/numpy/ma/core.py b/numpy/ma/core.py index a09ec6bdb..407869362 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -3937,11 +3937,13 @@ class MaskedArray(ndarray): reprs['data'] = np.array2string( self._insert_masked_print(), separator=", ", - prefix=indents['data'] + 'data=') + prefix=indents['data'] + 'data=', + suffix=',') reprs['mask'] = np.array2string( self._mask, separator=", ", - prefix=indents['mask'] + 'mask=') + prefix=indents['mask'] + 'mask=', + suffix=',') reprs['fill_value'] = repr(self.fill_value) if dtype_needed: reprs['dtype'] = np.core.arrayprint.dtype_short_repr(self.dtype) |
