diff options
author | RenaRuirui <renaxu@umich.edu> | 2020-04-25 14:23:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-25 21:23:58 +0300 |
commit | 619422b493eaf88c42373af1725ac0aa2297fa91 (patch) | |
tree | b4a735be467d23efca13e77b897a16fcd421fe59 /numpy/ma/tests/test_extras.py | |
parent | 59984a3596e00e088b10c58f02856e8088fcd4df (diff) | |
download | numpy-619422b493eaf88c42373af1725ac0aa2297fa91.tar.gz |
BUG: fix AttributeError on accessing object in nested MaskedArray. (#15949)
* BUG: fix AttributeError on accessing object in nested MaskedArray
Co-authored-by: Rena Xu <renaxu@Renas-MacBook-Pro.local>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: vagrant <vagrant@vagrant.vm>
Diffstat (limited to 'numpy/ma/tests/test_extras.py')
-rw-r--r-- | numpy/ma/tests/test_extras.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index 1c8610625..d237829cb 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -64,6 +64,28 @@ class TestGeneric: control = array([[(1, (1, 1))]], mask=[[(1, (1, 1))]], dtype=dt) assert_equal(test, control) + def test_masked_all_with_object_nested(self): + # Test masked_all works with nested array with dtype of an 'object' + # refers to issue #15895 + my_dtype = np.dtype([('b', ([('c', object)], (1,)))]) + masked_arr = np.ma.masked_all((1,), my_dtype) + + assert_equal(type(masked_arr['b']), np.ma.core.MaskedArray) + assert_equal(type(masked_arr['b']['c']), np.ma.core.MaskedArray) + assert_equal(len(masked_arr['b']['c']), 1) + assert_equal(masked_arr['b']['c'].shape, (1, 1)) + assert_equal(masked_arr['b']['c']._fill_value.shape, ()) + + def test_masked_all_with_object(self): + # same as above except that the array is not nested + my_dtype = np.dtype([('b', (object, (1,)))]) + masked_arr = np.ma.masked_all((1,), my_dtype) + + assert_equal(type(masked_arr['b']), np.ma.core.MaskedArray) + assert_equal(len(masked_arr['b']), 1) + assert_equal(masked_arr['b'].shape, (1, 1)) + assert_equal(masked_arr['b']._fill_value.shape, ()) + def test_masked_all_like(self): # Tests masked_all # Standard dtype |