diff options
author | Laura Martens <laura.d.martens@icloud.com> | 2021-05-12 12:35:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 12:35:14 +0200 |
commit | bb745921ac6c27d6caf9b76663668e5b9f28abac (patch) | |
tree | cb2e74269770ba9fcd6936ded25e9d2dceda75b1 /numpy/ma/tests/test_extras.py | |
parent | fb586a4f5760efaae57a9251ed98c4ebd3edcdf8 (diff) | |
download | numpy-bb745921ac6c27d6caf9b76663668e5b9f28abac.tar.gz |
BUG: fixed ma.average ignoring masked weights (#18960)
Closes #10438
Co-authored-by: mecopur <mecopur@outlook.com>
Diffstat (limited to 'numpy/ma/tests/test_extras.py')
-rw-r--r-- | numpy/ma/tests/test_extras.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index d237829cb..e735b9bc7 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -292,6 +292,23 @@ class TestAverage: assert_almost_equal(wav1.real, expected1.real) assert_almost_equal(wav1.imag, expected1.imag) + def test_masked_weights(self): + # Test with masked weights. + # (Regression test for https://github.com/numpy/numpy/issues/10438) + a = np.ma.array(np.arange(9).reshape(3, 3), + mask=[[1, 0, 0], [1, 0, 0], [0, 0, 0]]) + weights_unmasked = masked_array([5, 28, 31], mask=False) + weights_masked = masked_array([5, 28, 31], mask=[1, 0, 0]) + + avg_unmasked = average(a, axis=0, + weights=weights_unmasked, returned=False) + expected_unmasked = np.array([6.0, 5.21875, 6.21875]) + assert_almost_equal(avg_unmasked, expected_unmasked) + + avg_masked = average(a, axis=0, weights=weights_masked, returned=False) + expected_masked = np.array([6.0, 5.576271186440678, 6.576271186440678]) + assert_almost_equal(avg_masked, expected_masked) + class TestConcatenator: # Tests for mr_, the equivalent of r_ for masked arrays. |