diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-10-19 12:45:10 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2018-10-20 14:09:19 -0600 |
commit | 046cd82608951f68b09f5c9e749d1193b41f2328 (patch) | |
tree | 09b35f83df7097616a527e53cfa80cde0f40c08e /numpy/ma/tests | |
parent | 5e6ff3f4992c99e145d8c569cc409058ef53c937 (diff) | |
download | numpy-046cd82608951f68b09f5c9e749d1193b41f2328.tar.gz |
BUG: Fix MaskedArray fill_value type conversion.
Fixes the regression introduced by #10211 where the masked array fill
value type was not properly converted by astype.
Closes #12070.
Diffstat (limited to 'numpy/ma/tests')
-rw-r--r-- | numpy/ma/tests/test_core.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index aa7672daa..50ab6e1de 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -4985,7 +4985,7 @@ def test_ufunc_with_out_varied(): assert_equal(res_pos.data, expected.data) -def test_astype(): +def test_astype_mask_ordering(): descr = [('v', int, 3), ('x', [('y', float)])] x = array([ [([1, 2, 3], (1.0,)), ([1, 2, 3], (2.0,))], @@ -5017,6 +5017,28 @@ def test_astype(): assert_(x_f2.mask.flags.f_contiguous) +dts = [np.dtype(dt_) for dt_ in '?bhilqBHILQefdgFD'] +ids = [dt_.char for dt_ in dts] + +@pytest.mark.parametrize('dt1', dts, ids=ids) +@pytest.mark.parametrize('dt2', dts, ids=ids) +@pytest.mark.filterwarnings('ignore::numpy.ComplexWarning') +def test_astype_basic(dt1, dt2): + # See gh-12070 + src = np.ma.array(ones(3, dt1), fill_value=1) + dst = src.astype(dt2) + + assert_(src.fill_value == 1) + assert_(src.dtype == dt1) + assert_(src.fill_value.dtype == dt1) + + assert_(dst.fill_value == 1) + assert_(dst.dtype == dt2) + assert_(dst.fill_value.dtype == dt2) + + assert_equal(src, dst) + + def test_fieldless_void(): dt = np.dtype([]) # a void dtype with no fields x = np.empty(4, dt) |