diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-05-23 12:12:06 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-05-23 12:12:06 -0600 |
commit | 59a7b250d4076d58c8b48bdf3800f2b1eac41e1b (patch) | |
tree | 503a4d96e760b789f47eca276a881059e5fb6a48 | |
parent | 313a9b20e51bc0adb2ac56a2d4ac702dcb8c21fa (diff) | |
parent | d805e9b66228e68a0eb14d901cd350159c49af18 (diff) | |
download | numpy-59a7b250d4076d58c8b48bdf3800f2b1eac41e1b.tar.gz |
Merge pull request #7658 from saimn/fix-ma-repr
BUG: fix incorrect printing of 1D masked arrays
-rw-r--r-- | numpy/ma/core.py | 11 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 9 |
2 files changed, 17 insertions, 3 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index dcbd97a3b..360ef694e 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2709,8 +2709,11 @@ class MaskedArray(ndarray): _defaultmask = nomask _defaulthardmask = False _baseclass = ndarray - # Maximum number of elements per axis used when printing an array. + + # Maximum number of elements per axis used when printing an array. The + # 1d case is handled separately because we need more values in this case. _print_width = 100 + _print_width_1d = 1500 def __new__(cls, data=None, mask=nomask, dtype=None, copy=False, subok=True, ndmin=0, fill_value=None, keep_mask=True, @@ -3796,9 +3799,11 @@ class MaskedArray(ndarray): mask = m # For big arrays, to avoid a costly conversion to the # object dtype, extract the corners before the conversion. + print_width = (self._print_width if self.ndim > 1 + else self._print_width_1d) for axis in range(self.ndim): - if data.shape[axis] > self._print_width: - ind = self._print_width // 2 + if data.shape[axis] > print_width: + ind = print_width // 2 arr = np.split(data, (ind, -ind), axis=axis) data = np.concatenate((arr[0], arr[2]), axis=axis) arr = np.split(mask, (ind, -ind), axis=axis) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 88bf91211..0a3226f27 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -451,6 +451,15 @@ class TestMaskedArray(TestCase): ' mask = [False True False],\n' ' fill_value = 999999)\n') + a = np.ma.arange(2000) + a[1:50] = np.ma.masked + assert_equal( + repr(a), + 'masked_array(data = [0 -- -- ..., 1997 1998 1999],\n' + ' mask = [False True True ..., False False False],\n' + ' fill_value = 999999)\n' + ) + def test_pickling(self): # Tests pickling a = arange(10) |