diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-12-18 21:20:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-18 21:20:52 -0800 |
commit | 0f13a2e7fa626dbde62bdda7a92fc0a6361981ba (patch) | |
tree | 80ee22f648e32636451d704ca37f52144919af32 /numpy/ma/tests | |
parent | c4df171480cbaf8f04705107c2a2776e0d4d7804 (diff) | |
parent | 669b1cc1456b23294550177a850b799f071958bb (diff) | |
download | numpy-0f13a2e7fa626dbde62bdda7a92fc0a6361981ba.tar.gz |
Merge pull request #10211 from mhvk/ma-astype-alternative
MAINT,ENH: remove MaskedArray.astype, as the base type does everything.
Diffstat (limited to 'numpy/ma/tests')
-rw-r--r-- | numpy/ma/tests/test_core.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index cc447e37e..2a5a65e5c 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -5037,10 +5037,37 @@ def test_ufunc_with_output(): y = np.add(x, 1., out=x) assert_(y is x) + def test_astype(): descr = [('v', int, 3), ('x', [('y', float)])] - x = array(([1, 2, 3], (1.0,)), dtype=descr) - assert_equal(x, x.astype(descr)) + x = array([ + [([1, 2, 3], (1.0,)), ([1, 2, 3], (2.0,))], + [([1, 2, 3], (3.0,)), ([1, 2, 3], (4.0,))]], dtype=descr) + x[0]['v'][0] = np.ma.masked + + x_a = x.astype(descr) + assert x_a.dtype.names == np.dtype(descr).names + assert x_a.mask.dtype.names == np.dtype(descr).names + assert_equal(x, x_a) + + assert_(x is x.astype(x.dtype, copy=False)) + assert_equal(type(x.astype(x.dtype, subok=False)), np.ndarray) + + x_f = x.astype(x.dtype, order='F') + assert_(x_f.flags.f_contiguous) + assert_(x_f.mask.flags.f_contiguous) + + # Also test the same indirectly, via np.array + x_a2 = np.array(x, dtype=descr, subok=True) + assert x_a2.dtype.names == np.dtype(descr).names + assert x_a2.mask.dtype.names == np.dtype(descr).names + assert_equal(x, x_a2) + + assert_(x is np.array(x, dtype=descr, copy=False, subok=True)) + + x_f2 = np.array(x, dtype=x.dtype, order='F', subok=True) + assert_(x_f2.flags.f_contiguous) + assert_(x_f2.mask.flags.f_contiguous) ############################################################################### |